@agntn/tools 0.0.0 → 0.1.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/README.md +5 -3
- package/dist/_chunks/libs/typebox.d.mts +888 -558
- package/dist/_chunks/libs/typebox.d.mts.map +1 -1
- package/dist/_chunks/libs/typebox.mjs +234 -3
- package/dist/_chunks/libs/typebox.mjs.map +1 -1
- package/dist/_chunks/src.mjs +158 -0
- package/dist/_chunks/src.mjs.map +1 -0
- package/dist/ai.d.mts +3 -4
- package/dist/ai.d.mts.map +1 -1
- package/dist/ai.mjs +1 -1
- package/dist/cli.d.mts +65 -0
- package/dist/cli.d.mts.map +1 -0
- package/dist/cli.mjs +393 -0
- package/dist/cli.mjs.map +1 -0
- package/dist/index.d.mts +38 -20
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +2 -90
- package/dist/mcp.d.mts +11 -8
- package/dist/mcp.d.mts.map +1 -1
- package/dist/mcp.mjs +8 -4
- package/dist/mcp.mjs.map +1 -1
- package/dist/omp.d.mts +4 -5
- package/dist/omp.d.mts.map +1 -1
- package/dist/omp.mjs +1 -1
- package/dist/pi.d.mts +3 -4
- package/dist/pi.d.mts.map +1 -1
- package/dist/pi.mjs +1 -1
- package/package.json +22 -18
- package/dist/index.mjs.map +0 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AddImmutable, AddImmutableDeferred, AddOptional, AddOptionalDeferred, AddReadonly, AddReadonlyDeferred, Any, ArrayOptions, BigInt, BigIntPattern, Boolean, Broaden, Call, CallConstruct, CanComposite, Capitalize, CapitalizeAction, CapitalizeDeferred, CapitalizeInstantiate, Codec, CollapseToObject, Compare, CompareResultDisjoint, CompareResultEqual, CompareResultLeftInside, CompareResultRightInside, Composite, Conditional, ConditionalAction, ConditionalDeferred, ConditionalInstantiate, Constructor, ConstructorOptions, ConstructorParameters, ConstructorParametersAction, ConstructorParametersDeferred, ConstructorParametersInstantiate, ConvertToIntegerKey, Cyclic, CyclicCandidates, CyclicCheck, CyclicDependencies, CyclicExtends, CyclicOptions, CyclicTarget, Decode, DecodeBuilder, Deferred, Dependent, DependentOptions, Distribute, Encode, EncodeBuilder, Enum, Evaluate, EvaluateAction, EvaluateDeferred, EvaluateDependent, EvaluateEnum, EvaluateInstantiate, EvaluateIntersect, EvaluateTemplateLiteral, EvaluateType, EvaluateUnion, EvaluateUnionFast, Exclude, ExcludeAction, ExcludeDeferred, ExcludeInstantiate, Extends, Extract, ExtractAction, ExtractDeferred, ExtractInstantiate, Flatten, FunctionOptions, Generic, Identifier, Immutable, Index, IndexAction, IndexDeferred, IndexInstantiate, Infer, InstanceType, InstanceTypeAction, InstanceTypeDeferred, InstanceTypeInstantiate, Instantiate, InstantiateCyclic, Integer, IntegerKey, IntegerPattern, Interface, InterfaceAction, InterfaceDeferred, InterfaceInstantiate, Intersect, IntersectOptions, InvalidLiteralValue, IsAny, IsArray, IsBigInt, IsBoolean, IsCall, IsCodec, IsConstructor, IsCyclic, IsDeferred, IsDependent, IsEnum, IsEnumValue, IsFunction, IsGeneric, IsIdentifier, IsImmutable, IsInfer, IsInteger, IsInterfaceDeferred, IsIntersect, IsKind, IsLiteral, IsLiteralBigInt, IsLiteralBoolean, IsLiteralNumber, IsLiteralString, IsLiteralValue, IsNever, IsNull, IsNumber, IsObject, IsOptional, IsParameter, IsReadonly, IsRecord, IsRef, IsRefine, IsRefinement, IsRest, IsSchema, IsString, IsSymbol, IsTemplateLiteral, IsTemplateLiteralDeferred, IsTemplateLiteralFinite, IsTemplateLiteralPattern, IsThis, IsTuple, IsTypeScriptEnumLike, IsUndefined, IsUnion, IsUnknown, IsUnsafe, IsVoid, KeyOf, KeyOfAction, KeyOfDeferred, KeyOfInstantiate, KeysToIndexer, Literal, LiteralTypeName, Lowercase, LowercaseAction, LowercaseDeferred, LowercaseInstantiate, Mapped, MappedAction, MappedDeferred, MappedInstantiate, Module, ModuleDeferred, ModuleInstantiate, Narrow, Never, NeverPattern, NonNullable, NonNullableAction, NonNullableDeferred, NonNullableInstantiate, Null, Number, NumberKey, NumberPattern, ObjectOptions, Omit, OmitAction, OmitDeferred, OmitInstantiate, Optional, Parameter, Parameters, ParametersAction, ParametersDeferred, ParametersInstantiate, ParsePatternIntoTypes, ParseTemplateIntoTypes, Partial, PartialAction, PartialDeferred, PartialInstantiate, Pick, PickAction, PickDeferred, PickInstantiate, Priority, PropertyKeys, PropertyValues, Readonly, ReadonlyObject, ReadonlyObjectAction, ReadonlyObjectDeferred, ReadonlyObjectInstantiate, ReadonlyType, Record as Record$1, RecordAction, RecordDeferred, RecordFromPattern, RecordInstantiate, RecordKey, RecordOptions, RecordPattern, RecordPatternToType, RecordValue, Ref, RefInstantiate, Refine, RefineAdd, RemoveImmutable, RemoveImmutableDeferred, RemoveOptional, RemoveOptionalDeferred, RemoveReadonly, RemoveReadonlyDeferred, Required, RequiredAction, RequiredArray, RequiredDeferred, RequiredInstantiate, Rest, ReturnType, ReturnTypeAction, ReturnTypeDeferred, ReturnTypeInstantiate, Script, Static, StaticAny, StaticArray, StaticBigInt, StaticBoolean, StaticCodec, StaticConstructor, StaticCyclic, StaticDecode, StaticDependent, StaticDirection, StaticEncode, StaticEnum, StaticEvaluate, StaticFunction, StaticInstantiatedParameters, StaticInteger, StaticIntersect, StaticLiteral, StaticNever, StaticNull, StaticNumber, StaticObject, StaticParse, StaticProperties, StaticRecord, StaticRef, StaticString, StaticSymbol, StaticTemplateLiteral, StaticThis, StaticTuple, StaticType, StaticUndefined, StaticUnion, StaticUnknown, StaticUnsafe, StaticVoid, String, StringKey, StringPattern, Symbol, TAddImmutable, TAddImmutableDeferred, TAddOptional, TAddOptionalDeferred, TAddReadonly, TAddReadonlyDeferred, TAny, TArray, TArrayOptions, TBigInt, TBoolean, TBroaden, TCall, TCallConstruct, TCanComposite, TCapitalize, TCapitalizeAction, TCapitalizeDeferred, TCapitalizeInstantiate, TCodec, TCollapseToObject, TCompare, TCompareResult, TComposite, TConditional, TConditionalAction, TConditionalDeferred, TConditionalInstantiate, TConstructor, TConstructorParameters, TConstructorParametersAction, TConstructorParametersDeferred, TConstructorParametersInstantiate, TConvertToIntegerKey, TCyclic, TCyclicCandidates, TCyclicCheck, TCyclicDependencies, TCyclicExtends, TCyclicTarget, TDecodeCallback, TDeferred, TDependent, TDistribute, TEncodeCallback, TEnum, TEnumValue, TEvaluate, TEvaluateAction, TEvaluateDeferred, TEvaluateDependent, TEvaluateEnum, TEvaluateInstantiate, TEvaluateIntersect, TEvaluateTemplateLiteral, TEvaluateType, TEvaluateUnion, TEvaluateUnionFast, TExclude, TExcludeAction, TExcludeDeferred, TExcludeInstantiate, TExtends, TExtract, TExtractAction, TExtractDeferred, TExtractInstantiate, TFlatten, TFormat, TFunction, TGeneric, TIdentifier, TImmutable, TIndex, TIndexAction, TIndexDeferred, TIndexInstantiate, TInfer, TInstanceType, TInstanceTypeAction, TInstanceTypeDeferred, TInstanceTypeInstantiate, TInstantiate, TInstantiateCyclic, TInteger, TIntegerKey, TInterface, TInterfaceAction, TInterfaceDeferred, TInterfaceInstantiate, TIntersect, TIntersectOptions, TIsTemplateLiteralFinite, TIsTemplateLiteralPattern, TKeyOf, TKeyOfAction, TKeyOfDeferred, TKeyOfInstantiate, TKeysToIndexer, TLiteral, TLiteralTypeName, TLiteralValue, TLowercase, TLowercaseAction, TLowercaseDeferred, TLowercaseInstantiate, TMapped, TMappedAction, TMappedDeferred, TMappedInstantiate, TModule, TModuleDeferred, TModuleInstantiate, TNarrow, TNever, TNonNullable, TNonNullableAction, TNonNullableDeferred, TNonNullableInstantiate, TNull, TNumber, TNumberKey, TNumberOptions, TObject, TObjectOptions, TOmit, TOmitAction, TOmitDeferred, TOmitInstantiate, TOptional, TParameter, TParameters, TParametersAction, TParametersDeferred, TParametersInstantiate, TParsePatternIntoTypes, TParseTemplateIntoTypes, TPartial, TPartialAction, TPartialDeferred, TPartialInstantiate, TPick, TPickAction, TPickDeferred, TPickInstantiate, TPriority, TProperties, TPropertyKeys, TPropertyValues, TReadonly, TReadonlyObject, TReadonlyObjectAction, TReadonlyObjectDeferred, TReadonlyObjectInstantiate, TRecord, TRecordAction, TRecordDeferred, TRecordInstantiate, TRecordKey, TRecordPattern, TRecordPatternToType, TRecordValue, TRef, TRefInstantiate, TRefine, TRefineAdd, TRefineCheckCallback, TRefineErrorCallback, TRefinement, TRemoveImmutable, TRemoveImmutableDeferred, TRemoveOptional, TRemoveOptionalDeferred, TRemoveReadonly, TRemoveReadonlyDeferred, TRequired, TRequiredAction, TRequiredArray, TRequiredDeferred, TRequiredInstantiate, TRest, TReturnType, TReturnTypeAction, TReturnTypeDeferred, TReturnTypeInstantiate, TSchema, TSchemaOptions, TScript, TScriptOptions, TStaticElements, TString, TStringKey, TStringOptions, TSymbol, TTemplateLiteral, TTemplateLiteralDecode, TTemplateLiteralDecodeUnsafe, TTemplateLiteralDeferred, TTemplateLiteralEncode, TTemplateLiteralFromString, TTemplateLiteralFromTypes, TTemplateLiteralStatic, TThis, TTuple, TTupleOptions, TTupleToIntersect, TTupleToUnion, TTypeScriptEnumLike, TTypeScriptEnumToEnumValues, TUncapitalize, TUncapitalizeAction, TUncapitalizeDeferred, TUncapitalizeInstantiate, TUndefined, TUnion, TUnionLast, TUnionToIntersect, TUnionToTuple, TUnknown, TUnsafe, TUppercase, TUppercaseAction, TUppercaseDeferred, TUppercaseInstantiate, TVoid, TWith, TWithAction, TWithDeferred, TWithInstantiate, TemplateLiteral, TemplateLiteralCreate, TemplateLiteralDecode, TemplateLiteralDecodeUnsafe, TemplateLiteralDeferred, TemplateLiteralEncode, TemplateLiteralFromString, TemplateLiteralFromTypes, This, Tuple, TupleOptions, TypeScriptEnumToEnumValues, Uncapitalize, UncapitalizeAction, UncapitalizeDeferred, UncapitalizeInstantiate, Undefined, Union, UnionOptions, Unknown, Unsafe, Uppercase, UppercaseAction, UppercaseDeferred, UppercaseInstantiate, Void, With, WithAction, WithDeferred, WithInstantiate, _Array_, _Function_, _Object_, index_d_exports, result_d_exports } from "./_chunks/libs/typebox.mjs";
|
|
2
2
|
/** Content block understood by MCP, Pi and OMP alike. */
|
|
3
|
-
type ToolContent = {
|
|
3
|
+
export type ToolContent = {
|
|
4
4
|
type: "text";
|
|
5
5
|
text: string;
|
|
6
6
|
} | {
|
|
@@ -9,7 +9,7 @@ type ToolContent = {
|
|
|
9
9
|
mimeType: string;
|
|
10
10
|
};
|
|
11
11
|
/** Text for the model plus details for the harness. */
|
|
12
|
-
interface ToolResult<Details = unknown> {
|
|
12
|
+
export interface ToolResult<Details = unknown> {
|
|
13
13
|
content: ToolContent[];
|
|
14
14
|
details: Details;
|
|
15
15
|
/** Set when the tool could not answer. Each adapter carries it to its host. */
|
|
@@ -22,15 +22,30 @@ interface ToolResult<Details = unknown> {
|
|
|
22
22
|
* - `write` changes state that the next call can undo or overwrite.
|
|
23
23
|
* - `destructive` deletes or overwrites what cannot be recovered.
|
|
24
24
|
*/
|
|
25
|
-
type ToolEffect = "read" | "write" | "destructive";
|
|
25
|
+
export type ToolEffect = "read" | "write" | "destructive";
|
|
26
|
+
/**
|
|
27
|
+
* How a tool reads on the command line. Without hints the command is the tool
|
|
28
|
+
* name without its package prefix, in kebab case, and every property is a flag.
|
|
29
|
+
*/
|
|
30
|
+
export interface ToolCliHints {
|
|
31
|
+
/** Command name instead of the derived one. */
|
|
32
|
+
readonly command?: string;
|
|
33
|
+
readonly aliases?: readonly string[];
|
|
34
|
+
/** Line in the command list. Defaults to the first sentence of `description`. */
|
|
35
|
+
readonly description?: string;
|
|
36
|
+
/** Properties taken in this order as positional arguments instead of flags. */
|
|
37
|
+
readonly positional?: readonly string[];
|
|
38
|
+
/** String properties that read stdin when given as `-`. */
|
|
39
|
+
readonly stdin?: readonly string[];
|
|
40
|
+
}
|
|
26
41
|
/** Per-call context the adapters hand to `execute`. */
|
|
27
|
-
interface ToolCallContext {
|
|
42
|
+
export interface ToolCallContext {
|
|
28
43
|
signal?: AbortSignal;
|
|
29
44
|
}
|
|
30
|
-
interface ToolDefinition<Input extends TObject = TObject, Details = unknown> {
|
|
45
|
+
export interface ToolDefinition<Input extends TObject = TObject, Details = unknown> {
|
|
31
46
|
/** Wire name, `<package>_<operation>`. */
|
|
32
47
|
readonly name: string;
|
|
33
|
-
/** Human label: MCP `title`, Pi and OMP `label`. */
|
|
48
|
+
/** Human label: MCP `title` and `annotations.title`, Pi and OMP `label`. */
|
|
34
49
|
readonly title: string;
|
|
35
50
|
/** Complete instruction for the model. MCP clients see nothing else. */
|
|
36
51
|
readonly description: string;
|
|
@@ -44,6 +59,8 @@ interface ToolDefinition<Input extends TObject = TObject, Details = unknown> {
|
|
|
44
59
|
/** The call reaches outside the local machine. */
|
|
45
60
|
readonly openWorld?: boolean;
|
|
46
61
|
readonly input: Input;
|
|
62
|
+
/** Command line shape for `@agntn/tools/cli`. No other surface reads it. */
|
|
63
|
+
readonly cli?: ToolCliHints;
|
|
47
64
|
/**
|
|
48
65
|
* Runs the tool on input that already passed {@link validateInput}.
|
|
49
66
|
*
|
|
@@ -53,11 +70,11 @@ interface ToolDefinition<Input extends TObject = TObject, Details = unknown> {
|
|
|
53
70
|
execute(input: Static<Input>, context: ToolCallContext): ToolResult<Details> | Promise<ToolResult<Details>>;
|
|
54
71
|
}
|
|
55
72
|
/** Thrown when a tool definition breaks a contract every surface relies on. */
|
|
56
|
-
declare class ToolDefinitionError extends Error {
|
|
73
|
+
export declare class ToolDefinitionError extends Error {
|
|
57
74
|
name: string;
|
|
58
75
|
}
|
|
59
76
|
/** Thrown by {@link invokeTool} when the arguments fail the tool schema. */
|
|
60
|
-
declare class ToolInputError extends Error {
|
|
77
|
+
export declare class ToolInputError extends Error {
|
|
61
78
|
name: string;
|
|
62
79
|
/** One validation failure per line. Only these line breaks are the core's own. */
|
|
63
80
|
readonly lines: readonly string[];
|
|
@@ -72,7 +89,7 @@ declare class ToolInputError extends Error {
|
|
|
72
89
|
* @param tool - Tool definition.
|
|
73
90
|
* @returns {ToolDefinition<Input, Details>} The same definition, typed.
|
|
74
91
|
*/
|
|
75
|
-
declare function defineTool<const Input extends TObject, Details>(tool: ToolDefinition<Input, Details>): ToolDefinition<Input, Details>;
|
|
92
|
+
export declare function defineTool<const Input extends TObject, Details>(tool: ToolDefinition<Input, Details>): ToolDefinition<Input, Details>;
|
|
76
93
|
/**
|
|
77
94
|
* The input schema as the plain JSON Schema object every host receives.
|
|
78
95
|
*
|
|
@@ -82,7 +99,7 @@ declare function defineTool<const Input extends TObject, Details>(tool: ToolDefi
|
|
|
82
99
|
* @param tool - Tool whose schema to emit.
|
|
83
100
|
* @returns {Record<string, unknown>} JSON Schema document.
|
|
84
101
|
*/
|
|
85
|
-
declare function wireSchema(tool: ToolDefinition): Record<string, unknown>;
|
|
102
|
+
export declare function wireSchema(tool: ToolDefinition): Record<string, unknown>;
|
|
86
103
|
/**
|
|
87
104
|
* Indexes tools by name.
|
|
88
105
|
*
|
|
@@ -92,8 +109,8 @@ declare function wireSchema(tool: ToolDefinition): Record<string, unknown>;
|
|
|
92
109
|
* @param tools - Tools to index.
|
|
93
110
|
* @returns {ReadonlyMap<string, ToolDefinition>} Tools by wire name.
|
|
94
111
|
*/
|
|
95
|
-
declare function indexTools(tools: readonly ToolDefinition[]): ReadonlyMap<string, ToolDefinition>;
|
|
96
|
-
type InputCheck<Input extends TObject> = {
|
|
112
|
+
export declare function indexTools(tools: readonly ToolDefinition[]): ReadonlyMap<string, ToolDefinition>;
|
|
113
|
+
export type InputCheck<Input extends TObject> = {
|
|
97
114
|
ok: true;
|
|
98
115
|
value: Static<Input>;
|
|
99
116
|
} | {
|
|
@@ -105,15 +122,16 @@ type InputCheck<Input extends TObject> = {
|
|
|
105
122
|
*
|
|
106
123
|
* Runs on every surface, not only MCP: a host may skip its own validation, and
|
|
107
124
|
* OMP's omptype drops `pattern` from the schema it emits. The message has one
|
|
108
|
-
* line per failure: an undeclared key names itself with the keys
|
|
109
|
-
* takes, and an enum failure names the allowed values, so the
|
|
110
|
-
* go back to the tool list and guess. Format from agntn/hashes
|
|
125
|
+
* line per failure: an undeclared key names itself with the keys its object
|
|
126
|
+
* takes, at any depth, and an enum failure names the allowed values, so the
|
|
127
|
+
* caller does not go back to the tool list and guess. Format from agntn/hashes
|
|
128
|
+
* (#58). TypeBox stops at eight errors, so root keys are read off the arguments.
|
|
111
129
|
*
|
|
112
130
|
* @param tool - Tool whose schema applies.
|
|
113
131
|
* @param args - Arguments as received from the host.
|
|
114
132
|
* @returns {InputCheck<Input>} The typed value, or the failures, one per line.
|
|
115
133
|
*/
|
|
116
|
-
declare function validateInput<Input extends TObject>(tool: ToolDefinition<Input, unknown>, args: unknown): InputCheck<Input>;
|
|
134
|
+
export declare function validateInput<Input extends TObject>(tool: ToolDefinition<Input, unknown>, args: unknown): InputCheck<Input>;
|
|
117
135
|
/**
|
|
118
136
|
* Validates and runs a tool. Every adapter calls through here.
|
|
119
137
|
*
|
|
@@ -123,7 +141,7 @@ declare function validateInput<Input extends TObject>(tool: ToolDefinition<Input
|
|
|
123
141
|
* @returns {Promise<ToolResult>} The executor's result, unchanged.
|
|
124
142
|
* @throws {ToolInputError} When the arguments fail the schema.
|
|
125
143
|
*/
|
|
126
|
-
declare function invokeTool(tool: ToolDefinition, args: unknown, context?: ToolCallContext): Promise<ToolResult>;
|
|
144
|
+
export declare function invokeTool(tool: ToolDefinition, args: unknown, context?: ToolCallContext): Promise<ToolResult>;
|
|
127
145
|
/**
|
|
128
146
|
* Makes a value safe for one line of terminal or protocol text.
|
|
129
147
|
*
|
|
@@ -135,13 +153,13 @@ declare function invokeTool(tool: ToolDefinition, args: unknown, context?: ToolC
|
|
|
135
153
|
* @param value - Value to render.
|
|
136
154
|
* @returns {string} Single-line text.
|
|
137
155
|
*/
|
|
138
|
-
declare function sanitizeLine(value: unknown): string;
|
|
156
|
+
export declare function sanitizeLine(value: unknown): string;
|
|
139
157
|
/**
|
|
140
158
|
* Text of a result, for hosts that carry failures as thrown errors.
|
|
141
159
|
*
|
|
142
160
|
* @param result - Tool result.
|
|
143
161
|
* @returns {string} Text blocks joined by newlines.
|
|
144
162
|
*/
|
|
145
|
-
declare function resultText(result: ToolResult): string;
|
|
146
|
-
export { type AddImmutable, type AddImmutableDeferred, type AddOptional, type AddOptionalDeferred, type AddReadonly, type AddReadonlyDeferred, type Any, type _Array_ as Array, type _Array_, type ArrayOptions, type BigInt, type BigIntPattern, type Boolean, type Broaden, type Call, type CallConstruct, type CanComposite, type Capitalize, type CapitalizeAction, type CapitalizeDeferred, type CapitalizeInstantiate, type Codec, type CollapseToObject, type Compare, type CompareResultDisjoint, type CompareResultEqual, type CompareResultLeftInside, type CompareResultRightInside, type Composite, type Conditional, type ConditionalAction, type ConditionalDeferred, type ConditionalInstantiate, type Constructor, type ConstructorOptions, type ConstructorParameters, type ConstructorParametersAction, type ConstructorParametersDeferred, type ConstructorParametersInstantiate, type ConvertToIntegerKey, type Cyclic, type CyclicCandidates, type CyclicCheck, type CyclicDependencies, type CyclicExtends, type CyclicOptions, type CyclicTarget, type Decode, type DecodeBuilder, type Deferred, type Dependent, type DependentOptions, type Distribute, type Encode, type EncodeBuilder, type Enum, type Evaluate, type EvaluateAction, type EvaluateDeferred, type EvaluateDependent, type EvaluateEnum, type EvaluateInstantiate, type EvaluateIntersect, type EvaluateTemplateLiteral, type EvaluateType, type EvaluateUnion, type EvaluateUnionFast, type Exclude, type ExcludeAction, type ExcludeDeferred, type ExcludeInstantiate, type Extends, type result_d_exports as ExtendsResult, type Extract, type ExtractAction, type ExtractDeferred, type ExtractInstantiate, type Flatten, type _Function_ as Function, type _Function_, type FunctionOptions, type Generic, type Identifier, type Immutable, type Index, type IndexAction, type IndexDeferred, type IndexInstantiate, type Infer, InputCheck, type InstanceType, type InstanceTypeAction, type InstanceTypeDeferred, type InstanceTypeInstantiate, type Instantiate, type InstantiateCyclic, type Integer, type IntegerKey, type IntegerPattern, type Interface, type InterfaceAction, type InterfaceDeferred, type InterfaceInstantiate, type Intersect, type IntersectOptions, type InvalidLiteralValue, type IsAny, type IsArray, type IsBigInt, type IsBoolean, type IsCall, type IsCodec, type IsConstructor, type IsCyclic, type IsDeferred, type IsDependent, type IsEnum, type IsEnumValue, type IsFunction, type IsGeneric, type IsIdentifier, type IsImmutable, type IsInfer, type IsInteger, type IsInterfaceDeferred, type IsIntersect, type IsKind, type IsLiteral, type IsLiteralBigInt, type IsLiteralBoolean, type IsLiteralNumber, type IsLiteralString, type IsLiteralValue, type IsNever, type IsNull, type IsNumber, type IsObject, type IsOptional, type IsParameter, type IsReadonly, type IsRecord, type IsRef, type IsRefine, type IsRefinement, type IsRest, type IsSchema, type IsString, type IsSymbol, type IsTemplateLiteral, type IsTemplateLiteralDeferred, type IsTemplateLiteralFinite, type IsTemplateLiteralPattern, type IsThis, type IsTuple, type IsTypeScriptEnumLike, type IsUndefined, type IsUnion, type IsUnknown, type IsUnsafe, type IsVoid, type KeyOf, type KeyOfAction, type KeyOfDeferred, type KeyOfInstantiate, type KeysToIndexer, type Literal, type LiteralTypeName, type Lowercase, type LowercaseAction, type LowercaseDeferred, type LowercaseInstantiate, type Mapped, type MappedAction, type MappedDeferred, type MappedInstantiate, type Module, type ModuleDeferred, type ModuleInstantiate, type Narrow, type Never, type NeverPattern, type NonNullable, type NonNullableAction, type NonNullableDeferred, type NonNullableInstantiate, type Null, type Number, type NumberKey, type NumberPattern, type _Object_ as Object, type _Object_, type ObjectOptions, type Omit, type OmitAction, type OmitDeferred, type OmitInstantiate, type Optional, type Parameter, type Parameters, type ParametersAction, type ParametersDeferred, type ParametersInstantiate, type ParsePatternIntoTypes, type ParseTemplateIntoTypes, type Partial, type PartialAction, type PartialDeferred, type PartialInstantiate, type Pick, type PickAction, type PickDeferred, type PickInstantiate, type Priority, type PropertyKeys, type PropertyValues, type Readonly, type ReadonlyObject, type ReadonlyObjectAction, type ReadonlyObjectDeferred, type ReadonlyObjectInstantiate, type ReadonlyType, type Record$1 as Record, type RecordAction, type RecordDeferred, type RecordFromPattern, type RecordInstantiate, type RecordKey, type RecordOptions, type RecordPattern, type RecordPatternToType, type RecordValue, type Ref, type RefInstantiate, type Refine, type RefineAdd, type RemoveImmutable, type RemoveImmutableDeferred, type RemoveOptional, type RemoveOptionalDeferred, type RemoveReadonly, type RemoveReadonlyDeferred, type Required, type RequiredAction, type RequiredArray, type RequiredDeferred, type RequiredInstantiate, type Rest, type ReturnType, type ReturnTypeAction, type ReturnTypeDeferred, type ReturnTypeInstantiate, type Script, type Static, type StaticAny, type StaticArray, type StaticBigInt, type StaticBoolean, type StaticCodec, type StaticConstructor, type StaticCyclic, type StaticDecode, type StaticDependent, type StaticDirection, type StaticEncode, type StaticEnum, type StaticEvaluate, type StaticFunction, type StaticInstantiatedParameters, type StaticInteger, type StaticIntersect, type StaticLiteral, type StaticNever, type StaticNull, type StaticNumber, type StaticObject, type StaticParse, type StaticProperties, type StaticRecord, type StaticRef, type StaticString, type StaticSymbol, type StaticTemplateLiteral, type StaticThis, type StaticTuple, type StaticType, type StaticUndefined, type StaticUnion, type StaticUnknown, type StaticUnsafe, type StaticVoid, type String, type StringKey, type StringPattern, type Symbol, type TAddImmutable, type TAddImmutableDeferred, type TAddOptional, type TAddOptionalDeferred, type TAddReadonly, type TAddReadonlyDeferred, type TAny, type TArray, type TArrayOptions, type TBigInt, type TBoolean, type TBroaden, type TCall, type TCallConstruct, type TCanComposite, type TCapitalize, type TCapitalizeAction, type TCapitalizeDeferred, type TCapitalizeInstantiate, type TCodec, type TCollapseToObject, type TCompare, type TCompareResult, type TComposite, type TConditional, type TConditionalAction, type TConditionalDeferred, type TConditionalInstantiate, type TConstructor, type TConstructorParameters, type TConstructorParametersAction, type TConstructorParametersDeferred, type TConstructorParametersInstantiate, type TConvertToIntegerKey, type TCyclic, type TCyclicCandidates, type TCyclicCheck, type TCyclicDependencies, type TCyclicExtends, type TCyclicTarget, type TDecodeCallback, type TDeferred, type TDependent, type TDistribute, type TEncodeCallback, type TEnum, type TEnumValue, type TEvaluate, type TEvaluateAction, type TEvaluateDeferred, type TEvaluateDependent, type TEvaluateEnum, type TEvaluateInstantiate, type TEvaluateIntersect, type TEvaluateTemplateLiteral, type TEvaluateType, type TEvaluateUnion, type TEvaluateUnionFast, type TExclude, type TExcludeAction, type TExcludeDeferred, type TExcludeInstantiate, type TExtends, type TExtract, type TExtractAction, type TExtractDeferred, type TExtractInstantiate, type TFlatten, type TFormat, type TFunction, type TGeneric, type TIdentifier, type TImmutable, type TIndex, type TIndexAction, type TIndexDeferred, type TIndexInstantiate, type TInfer, type TInstanceType, type TInstanceTypeAction, type TInstanceTypeDeferred, type TInstanceTypeInstantiate, type TInstantiate, type TInstantiateCyclic, type TInteger, type TIntegerKey, type TInterface, type TInterfaceAction, type TInterfaceDeferred, type TInterfaceInstantiate, type TIntersect, type TIntersectOptions, type TIsTemplateLiteralFinite, type TIsTemplateLiteralPattern, type TKeyOf, type TKeyOfAction, type TKeyOfDeferred, type TKeyOfInstantiate, type TKeysToIndexer, type TLiteral, type TLiteralTypeName, type TLiteralValue, type TLowercase, type TLowercaseAction, type TLowercaseDeferred, type TLowercaseInstantiate, type TMapped, type TMappedAction, type TMappedDeferred, type TMappedInstantiate, type TModule, type TModuleDeferred, type TModuleInstantiate, type TNarrow, type TNever, type TNonNullable, type TNonNullableAction, type TNonNullableDeferred, type TNonNullableInstantiate, type TNull, type TNumber, type TNumberKey, type TNumberOptions, type TObject, type TObjectOptions, type TOmit, type TOmitAction, type TOmitDeferred, type TOmitInstantiate, type TOptional, type TParameter, type TParameters, type TParametersAction, type TParametersDeferred, type TParametersInstantiate, type TParsePatternIntoTypes, type TParseTemplateIntoTypes, type TPartial, type TPartialAction, type TPartialDeferred, type TPartialInstantiate, type TPick, type TPickAction, type TPickDeferred, type TPickInstantiate, type TPriority, type TProperties, type TPropertyKeys, type TPropertyValues, type TReadonly, type TReadonlyObject, type TReadonlyObjectAction, type TReadonlyObjectDeferred, type TReadonlyObjectInstantiate, type TRecord, type TRecordAction, type TRecordDeferred, type TRecordInstantiate, type TRecordKey, type TRecordPattern, type TRecordPatternToType, type TRecordValue, type TRef, type TRefInstantiate, type TRefine, type TRefineAdd, type TRefineCheckCallback, type TRefineErrorCallback, type TRefinement, type TRemoveImmutable, type TRemoveImmutableDeferred, type TRemoveOptional, type TRemoveOptionalDeferred, type TRemoveReadonly, type TRemoveReadonlyDeferred, type TRequired, type TRequiredAction, type TRequiredArray, type TRequiredDeferred, type TRequiredInstantiate, type TRest, type TReturnType, type TReturnTypeAction, type TReturnTypeDeferred, type TReturnTypeInstantiate, type TSchema, type TSchemaOptions, type TScript, type TScriptOptions, type TStaticElements, type TString, type TStringKey, type TStringOptions, type TSymbol, type TTemplateLiteral, type TTemplateLiteralDecode, type TTemplateLiteralDecodeUnsafe, type TTemplateLiteralDeferred, type TTemplateLiteralEncode, type TTemplateLiteralFromString, type TTemplateLiteralFromTypes, type TTemplateLiteralStatic, type TThis, type TTuple, type TTupleOptions, type TTupleToIntersect, type TTupleToUnion, type TTypeScriptEnumLike, type TTypeScriptEnumToEnumValues, type TUncapitalize, type TUncapitalizeAction, type TUncapitalizeDeferred, type TUncapitalizeInstantiate, type TUndefined, type TUnion, type TUnionLast, type TUnionToIntersect, type TUnionToTuple, type TUnknown, type TUnsafe, type TUppercase, type TUppercaseAction, type TUppercaseDeferred, type TUppercaseInstantiate, type TVoid, type TWith, type TWithAction, type TWithDeferred, type TWithInstantiate, type TemplateLiteral, type TemplateLiteralCreate, type TemplateLiteralDecode, type TemplateLiteralDecodeUnsafe, type TemplateLiteralDeferred, type TemplateLiteralEncode, type TemplateLiteralFromString, type TemplateLiteralFromTypes, type This, ToolCallContext, ToolContent, ToolDefinition, ToolDefinitionError, ToolEffect, ToolInputError, ToolResult, type Tuple, type TupleOptions, index_d_exports as Type, type TypeScriptEnumToEnumValues, type Uncapitalize, type UncapitalizeAction, type UncapitalizeDeferred, type UncapitalizeInstantiate, type Undefined, type Union, type UnionOptions, type Unknown, type Unsafe, type Uppercase, type UppercaseAction, type UppercaseDeferred, type UppercaseInstantiate, type Void, type With, type WithAction, type WithDeferred, type WithInstantiate, defineTool, indexTools, invokeTool, resultText, sanitizeLine, validateInput, wireSchema };
|
|
163
|
+
export declare function resultText(result: ToolResult): string;
|
|
164
|
+
export { type AddImmutable, type AddImmutableDeferred, type AddOptional, type AddOptionalDeferred, type AddReadonly, type AddReadonlyDeferred, type Any, type _Array_ as Array, type _Array_, type ArrayOptions, type BigInt, type BigIntPattern, type Boolean, type Broaden, type Call, type CallConstruct, type CanComposite, type Capitalize, type CapitalizeAction, type CapitalizeDeferred, type CapitalizeInstantiate, type Codec, type CollapseToObject, type Compare, type CompareResultDisjoint, type CompareResultEqual, type CompareResultLeftInside, type CompareResultRightInside, type Composite, type Conditional, type ConditionalAction, type ConditionalDeferred, type ConditionalInstantiate, type Constructor, type ConstructorOptions, type ConstructorParameters, type ConstructorParametersAction, type ConstructorParametersDeferred, type ConstructorParametersInstantiate, type ConvertToIntegerKey, type Cyclic, type CyclicCandidates, type CyclicCheck, type CyclicDependencies, type CyclicExtends, type CyclicOptions, type CyclicTarget, type Decode, type DecodeBuilder, type Deferred, type Dependent, type DependentOptions, type Distribute, type Encode, type EncodeBuilder, type Enum, type Evaluate, type EvaluateAction, type EvaluateDeferred, type EvaluateDependent, type EvaluateEnum, type EvaluateInstantiate, type EvaluateIntersect, type EvaluateTemplateLiteral, type EvaluateType, type EvaluateUnion, type EvaluateUnionFast, type Exclude, type ExcludeAction, type ExcludeDeferred, type ExcludeInstantiate, type Extends, type result_d_exports as ExtendsResult, type Extract, type ExtractAction, type ExtractDeferred, type ExtractInstantiate, type Flatten, type _Function_ as Function, type _Function_, type FunctionOptions, type Generic, type Identifier, type Immutable, type Index, type IndexAction, type IndexDeferred, type IndexInstantiate, type Infer, type InstanceType, type InstanceTypeAction, type InstanceTypeDeferred, type InstanceTypeInstantiate, type Instantiate, type InstantiateCyclic, type Integer, type IntegerKey, type IntegerPattern, type Interface, type InterfaceAction, type InterfaceDeferred, type InterfaceInstantiate, type Intersect, type IntersectOptions, type InvalidLiteralValue, type IsAny, type IsArray, type IsBigInt, type IsBoolean, type IsCall, type IsCodec, type IsConstructor, type IsCyclic, type IsDeferred, type IsDependent, type IsEnum, type IsEnumValue, type IsFunction, type IsGeneric, type IsIdentifier, type IsImmutable, type IsInfer, type IsInteger, type IsInterfaceDeferred, type IsIntersect, type IsKind, type IsLiteral, type IsLiteralBigInt, type IsLiteralBoolean, type IsLiteralNumber, type IsLiteralString, type IsLiteralValue, type IsNever, type IsNull, type IsNumber, type IsObject, type IsOptional, type IsParameter, type IsReadonly, type IsRecord, type IsRef, type IsRefine, type IsRefinement, type IsRest, type IsSchema, type IsString, type IsSymbol, type IsTemplateLiteral, type IsTemplateLiteralDeferred, type IsTemplateLiteralFinite, type IsTemplateLiteralPattern, type IsThis, type IsTuple, type IsTypeScriptEnumLike, type IsUndefined, type IsUnion, type IsUnknown, type IsUnsafe, type IsVoid, type KeyOf, type KeyOfAction, type KeyOfDeferred, type KeyOfInstantiate, type KeysToIndexer, type Literal, type LiteralTypeName, type Lowercase, type LowercaseAction, type LowercaseDeferred, type LowercaseInstantiate, type Mapped, type MappedAction, type MappedDeferred, type MappedInstantiate, type Module, type ModuleDeferred, type ModuleInstantiate, type Narrow, type Never, type NeverPattern, type NonNullable, type NonNullableAction, type NonNullableDeferred, type NonNullableInstantiate, type Null, type Number, type NumberKey, type NumberPattern, type _Object_ as Object, type _Object_, type ObjectOptions, type Omit, type OmitAction, type OmitDeferred, type OmitInstantiate, type Optional, type Parameter, type Parameters, type ParametersAction, type ParametersDeferred, type ParametersInstantiate, type ParsePatternIntoTypes, type ParseTemplateIntoTypes, type Partial, type PartialAction, type PartialDeferred, type PartialInstantiate, type Pick, type PickAction, type PickDeferred, type PickInstantiate, type Priority, type PropertyKeys, type PropertyValues, type Readonly, type ReadonlyObject, type ReadonlyObjectAction, type ReadonlyObjectDeferred, type ReadonlyObjectInstantiate, type ReadonlyType, type Record$1 as Record, type RecordAction, type RecordDeferred, type RecordFromPattern, type RecordInstantiate, type RecordKey, type RecordOptions, type RecordPattern, type RecordPatternToType, type RecordValue, type Ref, type RefInstantiate, type Refine, type RefineAdd, type RemoveImmutable, type RemoveImmutableDeferred, type RemoveOptional, type RemoveOptionalDeferred, type RemoveReadonly, type RemoveReadonlyDeferred, type Required, type RequiredAction, type RequiredArray, type RequiredDeferred, type RequiredInstantiate, type Rest, type ReturnType, type ReturnTypeAction, type ReturnTypeDeferred, type ReturnTypeInstantiate, type Script, type Static, type StaticAny, type StaticArray, type StaticBigInt, type StaticBoolean, type StaticCodec, type StaticConstructor, type StaticCyclic, type StaticDecode, type StaticDependent, type StaticDirection, type StaticEncode, type StaticEnum, type StaticEvaluate, type StaticFunction, type StaticInstantiatedParameters, type StaticInteger, type StaticIntersect, type StaticLiteral, type StaticNever, type StaticNull, type StaticNumber, type StaticObject, type StaticParse, type StaticProperties, type StaticRecord, type StaticRef, type StaticString, type StaticSymbol, type StaticTemplateLiteral, type StaticThis, type StaticTuple, type StaticType, type StaticUndefined, type StaticUnion, type StaticUnknown, type StaticUnsafe, type StaticVoid, type String, type StringKey, type StringPattern, type Symbol, type TAddImmutable, type TAddImmutableDeferred, type TAddOptional, type TAddOptionalDeferred, type TAddReadonly, type TAddReadonlyDeferred, type TAny, type TArray, type TArrayOptions, type TBigInt, type TBoolean, type TBroaden, type TCall, type TCallConstruct, type TCanComposite, type TCapitalize, type TCapitalizeAction, type TCapitalizeDeferred, type TCapitalizeInstantiate, type TCodec, type TCollapseToObject, type TCompare, type TCompareResult, type TComposite, type TConditional, type TConditionalAction, type TConditionalDeferred, type TConditionalInstantiate, type TConstructor, type TConstructorParameters, type TConstructorParametersAction, type TConstructorParametersDeferred, type TConstructorParametersInstantiate, type TConvertToIntegerKey, type TCyclic, type TCyclicCandidates, type TCyclicCheck, type TCyclicDependencies, type TCyclicExtends, type TCyclicTarget, type TDecodeCallback, type TDeferred, type TDependent, type TDistribute, type TEncodeCallback, type TEnum, type TEnumValue, type TEvaluate, type TEvaluateAction, type TEvaluateDeferred, type TEvaluateDependent, type TEvaluateEnum, type TEvaluateInstantiate, type TEvaluateIntersect, type TEvaluateTemplateLiteral, type TEvaluateType, type TEvaluateUnion, type TEvaluateUnionFast, type TExclude, type TExcludeAction, type TExcludeDeferred, type TExcludeInstantiate, type TExtends, type TExtract, type TExtractAction, type TExtractDeferred, type TExtractInstantiate, type TFlatten, type TFormat, type TFunction, type TGeneric, type TIdentifier, type TImmutable, type TIndex, type TIndexAction, type TIndexDeferred, type TIndexInstantiate, type TInfer, type TInstanceType, type TInstanceTypeAction, type TInstanceTypeDeferred, type TInstanceTypeInstantiate, type TInstantiate, type TInstantiateCyclic, type TInteger, type TIntegerKey, type TInterface, type TInterfaceAction, type TInterfaceDeferred, type TInterfaceInstantiate, type TIntersect, type TIntersectOptions, type TIsTemplateLiteralFinite, type TIsTemplateLiteralPattern, type TKeyOf, type TKeyOfAction, type TKeyOfDeferred, type TKeyOfInstantiate, type TKeysToIndexer, type TLiteral, type TLiteralTypeName, type TLiteralValue, type TLowercase, type TLowercaseAction, type TLowercaseDeferred, type TLowercaseInstantiate, type TMapped, type TMappedAction, type TMappedDeferred, type TMappedInstantiate, type TModule, type TModuleDeferred, type TModuleInstantiate, type TNarrow, type TNever, type TNonNullable, type TNonNullableAction, type TNonNullableDeferred, type TNonNullableInstantiate, type TNull, type TNumber, type TNumberKey, type TNumberOptions, type TObject, type TObjectOptions, type TOmit, type TOmitAction, type TOmitDeferred, type TOmitInstantiate, type TOptional, type TParameter, type TParameters, type TParametersAction, type TParametersDeferred, type TParametersInstantiate, type TParsePatternIntoTypes, type TParseTemplateIntoTypes, type TPartial, type TPartialAction, type TPartialDeferred, type TPartialInstantiate, type TPick, type TPickAction, type TPickDeferred, type TPickInstantiate, type TPriority, type TProperties, type TPropertyKeys, type TPropertyValues, type TReadonly, type TReadonlyObject, type TReadonlyObjectAction, type TReadonlyObjectDeferred, type TReadonlyObjectInstantiate, type TRecord, type TRecordAction, type TRecordDeferred, type TRecordInstantiate, type TRecordKey, type TRecordPattern, type TRecordPatternToType, type TRecordValue, type TRef, type TRefInstantiate, type TRefine, type TRefineAdd, type TRefineCheckCallback, type TRefineErrorCallback, type TRefinement, type TRemoveImmutable, type TRemoveImmutableDeferred, type TRemoveOptional, type TRemoveOptionalDeferred, type TRemoveReadonly, type TRemoveReadonlyDeferred, type TRequired, type TRequiredAction, type TRequiredArray, type TRequiredDeferred, type TRequiredInstantiate, type TRest, type TReturnType, type TReturnTypeAction, type TReturnTypeDeferred, type TReturnTypeInstantiate, type TSchema, type TSchemaOptions, type TScript, type TScriptOptions, type TStaticElements, type TString, type TStringKey, type TStringOptions, type TSymbol, type TTemplateLiteral, type TTemplateLiteralDecode, type TTemplateLiteralDecodeUnsafe, type TTemplateLiteralDeferred, type TTemplateLiteralEncode, type TTemplateLiteralFromString, type TTemplateLiteralFromTypes, type TTemplateLiteralStatic, type TThis, type TTuple, type TTupleOptions, type TTupleToIntersect, type TTupleToUnion, type TTypeScriptEnumLike, type TTypeScriptEnumToEnumValues, type TUncapitalize, type TUncapitalizeAction, type TUncapitalizeDeferred, type TUncapitalizeInstantiate, type TUndefined, type TUnion, type TUnionLast, type TUnionToIntersect, type TUnionToTuple, type TUnknown, type TUnsafe, type TUppercase, type TUppercaseAction, type TUppercaseDeferred, type TUppercaseInstantiate, type TVoid, type TWith, type TWithAction, type TWithDeferred, type TWithInstantiate, type TemplateLiteral, type TemplateLiteralCreate, type TemplateLiteralDecode, type TemplateLiteralDecodeUnsafe, type TemplateLiteralDeferred, type TemplateLiteralEncode, type TemplateLiteralFromString, type TemplateLiteralFromTypes, type This, type Tuple, type TupleOptions, index_d_exports as Type, type TypeScriptEnumToEnumValues, type Uncapitalize, type UncapitalizeAction, type UncapitalizeDeferred, type UncapitalizeInstantiate, type Undefined, type Union, type UnionOptions, type Unknown, type Unsafe, type Uppercase, type UppercaseAction, type UppercaseDeferred, type UppercaseInstantiate, type Void, type With, type WithAction, type WithDeferred, type WithInstantiate };
|
|
147
165
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"mappings":";;YAgCY;EACN;EAAc;;EACd;EAAe;EAAc;;;iBAGlB,WAAW;EAC1B,SAAS;EACT,SAAS;;EAET;;;;;;;;;YAUU;;;;;iBAMK;;WAEN;WACA;;WAEA;;WAEA;;WAEA;;;iBAIM;EACf,SAAS;;iBAGM,eAAe,cAAc,UAAU,SAAS;;WAEtD;;WAEA;;WAEA;;WAEA;;WAEA;WACA,QAAQ;;WAER;;WAEA;WACA,OAAO;;WAEP,MAAM;;;;;;;EAOf,QACE,OAAO,OAAO,QACd,SAAS,kBACR,WAAW,WAAW,QAAQ,WAAW;;;qBAIjC,4BAA4B;EAC9B;;;qBAIE,uBAAuB;EACzB;;WAEA;;;;EAKT,YAAY;;;;;;;;wBAcE,iBAAiB,cAAc,SAAS,SACtD,MAAM,eAAe,OAAO,WAC3B,eAAe,OAAO;;;;;;;;;;wBA+GT,WAAW,MAAM,iBAAiB;;;;;;;;;;wBAalC,WAAW,gBAAgB,mBAAmB,oBAAoB;YAStE,WAAW,cAAc;EAC/B;EAAU,OAAO,OAAO;;EACxB;EAAW;;;;;;;;;;;;;;;;wBAgBD,cAAc,cAAc,SAC1C,MAAM,eAAe,iBACrB,gBACC,WAAW;;;;;;;;;;wBAyJQ,WACpB,MAAM,gBACN,eACA,UAAS,kBACR,QAAQ;;;;;;;;;;;;wBAmBK,aAAa;;;;;;;wBAab,WAAW,QAAQ"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,91 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
name = "ToolDefinitionError";
|
|
4
|
-
};
|
|
5
|
-
var ToolInputError = class extends Error {
|
|
6
|
-
name = "ToolInputError";
|
|
7
|
-
lines;
|
|
8
|
-
constructor(lines) {
|
|
9
|
-
super(lines.join("\n"));
|
|
10
|
-
this.lines = lines;
|
|
11
|
-
}
|
|
12
|
-
};
|
|
13
|
-
const TOOL_NAME = /^[a-z][a-z0-9_]{0,63}$/;
|
|
14
|
-
function defineTool(tool) {
|
|
15
|
-
if (!TOOL_NAME.test(tool.name)) throw new ToolDefinitionError(`Tool name ${JSON.stringify(tool.name)} must match ${TOOL_NAME}`);
|
|
16
|
-
if (typeof tool.input !== "object" || tool.input === null) throw new ToolDefinitionError(`${tool.name}: input must be a JSON Schema object; build it with Type from @agntn/tools, not from "typebox"`);
|
|
17
|
-
assertSchema(tool.name, wireSchema(tool));
|
|
18
|
-
return tool;
|
|
19
|
-
}
|
|
20
|
-
function assertSchema(toolName, node, path = "") {
|
|
21
|
-
const at = path || "/";
|
|
22
|
-
if (isOpenObject(node)) throw new ToolDefinitionError(`${toolName}: object at ${at} must be closed with additionalProperties: false`);
|
|
23
|
-
if (isLiteralUnion(node)) throw new ToolDefinitionError(`${toolName}: union of literals at ${at} must use Type.Enum`);
|
|
24
|
-
for (const [child, childPath] of schemaChildren(node, path)) assertSchema(toolName, child, childPath);
|
|
25
|
-
}
|
|
26
|
-
function isOpenObject(node) {
|
|
27
|
-
const properties = node.properties;
|
|
28
|
-
return node.type === "object" && properties !== void 0 && Object.keys(properties).length > 0 && node.additionalProperties !== false;
|
|
29
|
-
}
|
|
30
|
-
function isLiteralUnion(node) {
|
|
31
|
-
const anyOf = node.anyOf;
|
|
32
|
-
return anyOf !== void 0 && anyOf.length > 1 && anyOf.every((branch) => "const" in branch);
|
|
33
|
-
}
|
|
34
|
-
function isNode(value) {
|
|
35
|
-
return typeof value === "object" && value !== null;
|
|
36
|
-
}
|
|
37
|
-
function schemaChildren(node, path) {
|
|
38
|
-
const keyed = (keyword, childPath) => Object.entries(isNode(node[keyword]) ? node[keyword] : {}).flatMap(([key, child]) => isNode(child) ? [[child, childPath(key)]] : []);
|
|
39
|
-
const branches = Array.isArray(node.anyOf) ? node.anyOf : [];
|
|
40
|
-
return [
|
|
41
|
-
...keyed("properties", (key) => `${path}/${key}`),
|
|
42
|
-
...keyed("patternProperties", () => `${path}/*`),
|
|
43
|
-
...isNode(node.items) ? [[node.items, `${path}/items`]] : [],
|
|
44
|
-
...branches.filter(isNode).map((branch) => [branch, path])
|
|
45
|
-
];
|
|
46
|
-
}
|
|
47
|
-
function wireSchema(tool) {
|
|
48
|
-
return Object.fromEntries(Object.entries(tool.input));
|
|
49
|
-
}
|
|
50
|
-
function indexTools(tools) {
|
|
51
|
-
const byName = /* @__PURE__ */ new Map();
|
|
52
|
-
for (const tool of tools) {
|
|
53
|
-
if (byName.has(tool.name)) throw new ToolDefinitionError(`Duplicate tool name ${tool.name}`);
|
|
54
|
-
byName.set(tool.name, tool);
|
|
55
|
-
}
|
|
56
|
-
return byName;
|
|
57
|
-
}
|
|
58
|
-
function validateInput(tool, args) {
|
|
59
|
-
if (Check(tool.input, args)) return {
|
|
60
|
-
ok: true,
|
|
61
|
-
value: args
|
|
62
|
-
};
|
|
63
|
-
const declared = Object.keys(tool.input.properties);
|
|
64
|
-
const unknownKeys = args !== null && typeof args === "object" && !Array.isArray(args) ? Object.keys(args).filter((key) => !declared.includes(key)) : [];
|
|
65
|
-
const reported = new Set(unknownKeys.map((key) => `/${key.replaceAll("~", "~0").replaceAll("/", "~1")}`));
|
|
66
|
-
const lines = [...unknownKeys.map((key) => `Invalid arguments: unknown property ${JSON.stringify(key)}; takes ${declared.join(", ")}`), ...Errors(tool.input, args).filter((error) => error.keyword !== "additionalProperties" && !reported.has(error.instancePath)).map((error) => {
|
|
67
|
-
const allowed = error.keyword === "enum" ? error.params.allowedValues : void 0;
|
|
68
|
-
const message = Array.isArray(allowed) ? `must be one of ${allowed.join(", ")}` : error.message;
|
|
69
|
-
return `Invalid arguments at ${error.instancePath || "/"}: ${message}`;
|
|
70
|
-
})];
|
|
71
|
-
return {
|
|
72
|
-
ok: false,
|
|
73
|
-
lines: lines.length > 0 ? [...new Set(lines)] : ["Invalid arguments"]
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
async function invokeTool(tool, args, context = {}) {
|
|
77
|
-
const checked = validateInput(tool, args);
|
|
78
|
-
if (!checked.ok) throw new ToolInputError(checked.lines);
|
|
79
|
-
return await tool.execute(checked.value, context);
|
|
80
|
-
}
|
|
81
|
-
const LINE_BREAKING = /[\p{Cc}\p{Cf}\p{Zl}\p{Zp}]/gu;
|
|
82
|
-
const ESCAPE_SEQUENCE = /(?:\u001B\][\s\S]*?(?:\u0007|\u001B\u005C|\u009C))|[\u001B\u009B][[\]()#;?]*(?:\d{1,4}(?:[;:]\d{0,4})*)?[\dA-PR-TZcf-nq-uy=><~]/g;
|
|
83
|
-
function sanitizeLine(value) {
|
|
84
|
-
return String(value).replaceAll(ESCAPE_SEQUENCE, "").replaceAll(LINE_BREAKING, " ").replaceAll(/ {2,}/g, " ").trim();
|
|
85
|
-
}
|
|
86
|
-
function resultText(result) {
|
|
87
|
-
return result.content.flatMap((block) => block.type === "text" ? [block.text] : []).join("\n");
|
|
88
|
-
}
|
|
1
|
+
import { type_exports } from "./_chunks/libs/typebox.mjs";
|
|
2
|
+
import { ToolDefinitionError, ToolInputError, defineTool, indexTools, invokeTool, resultText, sanitizeLine, validateInput, wireSchema } from "./_chunks/src.mjs";
|
|
89
3
|
export { ToolDefinitionError, ToolInputError, type_exports as Type, defineTool, indexTools, invokeTool, resultText, sanitizeLine, validateInput, wireSchema };
|
|
90
|
-
|
|
91
|
-
//# sourceMappingURL=index.mjs.map
|
package/dist/mcp.d.mts
CHANGED
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
import { ToolDefinition } from "./index.mjs";
|
|
2
2
|
import { CallToolResult, Server, ToolAnnotations } from "@modelcontextprotocol/server";
|
|
3
|
-
interface McpServerInfo {
|
|
3
|
+
export interface McpServerInfo {
|
|
4
4
|
/** Server name, also used in the unknown-tool message. */
|
|
5
5
|
readonly name: string;
|
|
6
6
|
readonly version: string;
|
|
7
|
+
/** Display name for clients that show one, such as `Forges`. */
|
|
8
|
+
readonly title?: string;
|
|
9
|
+
/** Project home a client can link to. */
|
|
10
|
+
readonly websiteUrl?: string;
|
|
7
11
|
}
|
|
8
12
|
/**
|
|
9
|
-
* Maps a tool's declared effect to MCP annotations.
|
|
13
|
+
* Maps a tool's title and declared effect to MCP annotations. Claude Code reads its label here.
|
|
10
14
|
*
|
|
11
15
|
* @param tool - Tool to describe.
|
|
12
|
-
* @returns {ToolAnnotations}
|
|
16
|
+
* @returns {ToolAnnotations} Title and hints for the MCP client.
|
|
13
17
|
*/
|
|
14
|
-
declare function toolAnnotations(tool: ToolDefinition): ToolAnnotations;
|
|
18
|
+
export declare function toolAnnotations(tool: ToolDefinition): ToolAnnotations;
|
|
15
19
|
/**
|
|
16
20
|
* Error result with every line-forging character replaced.
|
|
17
21
|
*
|
|
@@ -23,7 +27,7 @@ declare function toolAnnotations(tool: ToolDefinition): ToolAnnotations;
|
|
|
23
27
|
* @param lines - Error lines.
|
|
24
28
|
* @returns {CallToolResult} MCP error result.
|
|
25
29
|
*/
|
|
26
|
-
declare function errorResult(...lines: readonly string[]): CallToolResult;
|
|
30
|
+
export declare function errorResult(...lines: readonly string[]): CallToolResult;
|
|
27
31
|
/**
|
|
28
32
|
* Creates an unconnected MCP server exposing the tools.
|
|
29
33
|
*
|
|
@@ -38,10 +42,9 @@ declare function errorResult(...lines: readonly string[]): CallToolResult;
|
|
|
38
42
|
* clients that see structured output prefer it over `content` and would hide
|
|
39
43
|
* the readable answer. Every fact a follow-up call needs belongs in the text.
|
|
40
44
|
*
|
|
41
|
-
* @param info - Server name and
|
|
45
|
+
* @param info - Server name, version and optional title and website, sent to the client as given.
|
|
42
46
|
* @param tools - Tools to serve.
|
|
43
47
|
* @returns {Server} Unconnected MCP server.
|
|
44
48
|
*/
|
|
45
|
-
declare function createMcpServer(info: McpServerInfo, tools: readonly ToolDefinition[]): Server;
|
|
46
|
-
export { McpServerInfo, createMcpServer, errorResult, toolAnnotations };
|
|
49
|
+
export declare function createMcpServer(info: McpServerInfo, tools: readonly ToolDefinition[]): Server;
|
|
47
50
|
//# sourceMappingURL=mcp.d.mts.map
|
package/dist/mcp.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp.d.mts","names":[],"sources":["../src/mcp.ts"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"mcp.d.mts","names":[],"sources":["../src/mcp.ts"],"mappings":";;iBAoBiB;;WAEN;WACA;;WAEA;;WAEA;;;;;;;;wBASK,gBAAgB,MAAM,iBAAiB;;;;;;;;;;;;wBAqBvC,eAAe,2BAA2B;;;;;;;;;;;;;;;;;;;wBAsB1C,gBAAgB,MAAM,eAAe,gBAAgB,mBAAmB"}
|
package/dist/mcp.mjs
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { ToolInputError, indexTools, invokeTool, sanitizeLine, wireSchema } from "./
|
|
1
|
+
import { ToolInputError, indexTools, invokeTool, sanitizeLine, wireSchema } from "./_chunks/src.mjs";
|
|
2
2
|
import { Server } from "@modelcontextprotocol/server";
|
|
3
3
|
function toolAnnotations(tool) {
|
|
4
4
|
return {
|
|
5
|
+
title: tool.title,
|
|
5
6
|
readOnlyHint: tool.effect === "read",
|
|
6
7
|
destructiveHint: tool.effect === "destructive",
|
|
7
8
|
idempotentHint: tool.idempotent ?? tool.effect === "read",
|
|
@@ -19,9 +20,12 @@ function errorResult(...lines) {
|
|
|
19
20
|
}
|
|
20
21
|
function createMcpServer(info, tools) {
|
|
21
22
|
const byName = indexTools(tools);
|
|
23
|
+
const { name, version, title, websiteUrl } = info;
|
|
22
24
|
const server = new Server({
|
|
23
|
-
name
|
|
24
|
-
version
|
|
25
|
+
name,
|
|
26
|
+
version,
|
|
27
|
+
title,
|
|
28
|
+
websiteUrl
|
|
25
29
|
}, { capabilities: { tools: {} } });
|
|
26
30
|
server.setRequestHandler("tools/list", () => ({ tools: tools.map((tool) => ({
|
|
27
31
|
name: tool.name,
|
|
@@ -32,7 +36,7 @@ function createMcpServer(info, tools) {
|
|
|
32
36
|
})) }));
|
|
33
37
|
server.setRequestHandler("tools/call", async (request, ctx) => {
|
|
34
38
|
const tool = byName.get(request.params.name);
|
|
35
|
-
if (!tool) return errorResult(`Unknown ${
|
|
39
|
+
if (!tool) return errorResult(`Unknown ${name} tool: ${JSON.stringify(request.params.name)}`);
|
|
36
40
|
try {
|
|
37
41
|
const result = await invokeTool(tool, request.params.arguments ?? {}, { signal: ctx.mcpReq.signal });
|
|
38
42
|
return {
|
package/dist/mcp.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp.mjs","names":[],"sources":["../src/mcp.ts"],"sourcesContent":["/**\n * MCP adapter: serves {@link ToolDefinition}s from an unconnected MCP server.\n */\n\nimport {\n Server,\n type CallToolResult,\n type Tool,\n type ToolAnnotations,\n} from \"@modelcontextprotocol/server\";\n\nimport {\n indexTools,\n invokeTool,\n sanitizeLine,\n ToolInputError,\n wireSchema,\n type ToolDefinition,\n} from \"./index.ts\";\n\nexport interface McpServerInfo {\n /** Server name, also used in the unknown-tool message. */\n readonly name: string;\n readonly version: string;\n}\n\n/**\n * Maps a tool's declared effect to MCP annotations.\n *\n * @param tool - Tool to describe.\n * @returns {ToolAnnotations}
|
|
1
|
+
{"version":3,"file":"mcp.mjs","names":[],"sources":["../src/mcp.ts"],"sourcesContent":["/**\n * MCP adapter: serves {@link ToolDefinition}s from an unconnected MCP server.\n */\n\nimport {\n Server,\n type CallToolResult,\n type Tool,\n type ToolAnnotations,\n} from \"@modelcontextprotocol/server\";\n\nimport {\n indexTools,\n invokeTool,\n sanitizeLine,\n ToolInputError,\n wireSchema,\n type ToolDefinition,\n} from \"./index.ts\";\n\nexport interface McpServerInfo {\n /** Server name, also used in the unknown-tool message. */\n readonly name: string;\n readonly version: string;\n /** Display name for clients that show one, such as `Forges`. */\n readonly title?: string;\n /** Project home a client can link to. */\n readonly websiteUrl?: string;\n}\n\n/**\n * Maps a tool's title and declared effect to MCP annotations. Claude Code reads its label here.\n *\n * @param tool - Tool to describe.\n * @returns {ToolAnnotations} Title and hints for the MCP client.\n */\nexport function toolAnnotations(tool: ToolDefinition): ToolAnnotations {\n return {\n title: tool.title,\n readOnlyHint: tool.effect === \"read\",\n destructiveHint: tool.effect === \"destructive\",\n idempotentHint: tool.idempotent ?? tool.effect === \"read\",\n openWorldHint: tool.openWorld ?? false,\n };\n}\n\n/**\n * Error result with every line-forging character replaced.\n *\n * The messages echo client-controlled values (a tool name, an argument) and\n * downstream error text, so they pass through here on every branch. Each line\n * is cleaned on its own, so only the breaks between the lines passed in\n * survive; a newline inside one line becomes a space.\n *\n * @param lines - Error lines.\n * @returns {CallToolResult} MCP error result.\n */\nexport function errorResult(...lines: readonly string[]): CallToolResult {\n return { content: [{ type: \"text\", text: lines.map(sanitizeLine).join(\"\\n\") }], isError: true };\n}\n\n/**\n * Creates an unconnected MCP server exposing the tools.\n *\n * Built on the low-level `Server` of MCP SDK v2, which the SDK marks\n * `@deprecated`, not on `McpServer`. `McpServer.registerTool` in 2.2.0 would\n * take the schema, but it answers `toString`, `constructor` and `__proto__` as\n * \"Tool toString disabled\" (a lookup that reaches `Object.prototype`), echoes a\n * raw tool name with newlines and escapes into its error, joins validation\n * failures into one line and passes a thrown message through unsanitized.\n *\n * `details` never reaches the client and `structuredContent` is never set:\n * clients that see structured output prefer it over `content` and would hide\n * the readable answer. Every fact a follow-up call needs belongs in the text.\n *\n * @param info - Server name, version and optional title and website, sent to the client as given.\n * @param tools - Tools to serve.\n * @returns {Server} Unconnected MCP server.\n */\nexport function createMcpServer(info: McpServerInfo, tools: readonly ToolDefinition[]): Server {\n const byName = indexTools(tools);\n const { name, version, title, websiteUrl } = info;\n const server = new Server({ name, version, title, websiteUrl }, { capabilities: { tools: {} } });\n\n server.setRequestHandler(\"tools/list\", () => ({\n tools: tools.map((tool): Tool => ({\n name: tool.name,\n title: tool.title,\n description: tool.description,\n inputSchema: wireSchema(tool) as Tool[\"inputSchema\"],\n annotations: toolAnnotations(tool),\n })),\n }));\n\n server.setRequestHandler(\"tools/call\", async (request, ctx) => {\n const tool = byName.get(request.params.name);\n if (!tool) {\n return errorResult(`Unknown ${name} tool: ${JSON.stringify(request.params.name)}`);\n }\n\n try {\n const result = await invokeTool(tool, request.params.arguments ?? {}, {\n signal: ctx.mcpReq.signal,\n });\n return {\n content: result.content,\n ...(result.isError === undefined ? {} : { isError: result.isError }),\n };\n } catch (error) {\n if (error instanceof ToolInputError) return errorResult(...error.lines);\n return errorResult(\n `${tool.name} failed: ${error instanceof Error ? error.message : String(error)}`,\n );\n }\n });\n\n return server;\n}\n"],"mappings":";;;;;;;;;CAoCA;AACE;AAEE,SAAA,YAAmB,GAAA,OAAA;CACnB,OAAA;EACA,SAAA,CAAA;GACA,MAAA;GACF,MAAA,MAAA,IAAA,YAAA,CAAA,CAAA,KAAA,IAAA;EACF,CAAA;;;;;;;;;;;EAaA;CACE,GAAA,EAAA,cAAO,EAAA,OAAA,CAAA,EAAA,EAAA,CAAA;CAAE,OAAA,kBAAU,qBAAA,EAAA,OAAA,MAAA,KAAA,UAAA;EAAE,MAAA,KAAM;EAAQ,OAAM,KAAA;EAAmC,aAAC,KAAA;EAAG,aAAS,WAAA,IAAA;EAAK,aAAA,gBAAA,IAAA;CAChG,EAAA,EAAA,EAAA"}
|
package/dist/omp.d.mts
CHANGED
|
@@ -2,12 +2,12 @@ import { ToolDefinition as ToolDefinition$1 } from "./index.mjs";
|
|
|
2
2
|
import { ExtensionAPI, Text, ToolDefinition } from "@oh-my-pi/pi-coding-agent";
|
|
3
3
|
type TextComponent = typeof Text;
|
|
4
4
|
/** The part of a host result a renderer reads. */
|
|
5
|
-
interface OmpResultView {
|
|
5
|
+
export interface OmpResultView {
|
|
6
6
|
readonly details?: unknown;
|
|
7
7
|
readonly isError?: boolean;
|
|
8
8
|
}
|
|
9
9
|
/** Per-tool renderer overrides, drawn with the host theme. */
|
|
10
|
-
interface OmpRenderers {
|
|
10
|
+
export interface OmpRenderers {
|
|
11
11
|
/** One-line summary of the arguments after the title. Sanitized by the adapter. */
|
|
12
12
|
describeCall?(args: Readonly<Record<string, unknown>>): unknown;
|
|
13
13
|
/** Short metadata after the badge, one entry per fact. Each entry is sanitized. */
|
|
@@ -18,7 +18,7 @@ interface OmpRenderers {
|
|
|
18
18
|
*/
|
|
19
19
|
renderResult?: ToolDefinition["renderResult"];
|
|
20
20
|
}
|
|
21
|
-
interface OmpToolOptions {
|
|
21
|
+
export interface OmpToolOptions {
|
|
22
22
|
/** The host `Text` component, imported by the extension from the package root. */
|
|
23
23
|
readonly Text: TextComponent;
|
|
24
24
|
/** Status-line renderers by tool name. */
|
|
@@ -36,6 +36,5 @@ interface OmpToolOptions {
|
|
|
36
36
|
* @param tools - Tools to register.
|
|
37
37
|
* @param options - Host `Text` and optional renderers.
|
|
38
38
|
*/
|
|
39
|
-
declare function registerOmpTools(pi: ExtensionAPI, tools: readonly ToolDefinition$1[], options: OmpToolOptions): void;
|
|
40
|
-
export { OmpRenderers, OmpResultView, OmpToolOptions, registerOmpTools };
|
|
39
|
+
export declare function registerOmpTools(pi: ExtensionAPI, tools: readonly ToolDefinition$1[], options: OmpToolOptions): void;
|
|
41
40
|
//# sourceMappingURL=omp.d.mts.map
|
package/dist/omp.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"omp.d.mts","names":["HostText","OmpToolDefinition","ToolDefinition"],"sources":["../src/omp.ts"],"mappings":";;KAyBK,uBAAuBA;;
|
|
1
|
+
{"version":3,"file":"omp.d.mts","names":["HostText","OmpToolDefinition","ToolDefinition"],"sources":["../src/omp.ts"],"mappings":";;KAyBK,uBAAuBA;;iBAIX;WACN;WACA;;;iBAIM;;EAEf,cAAc,MAAM,SAAS;;EAE7B,gBAAgB,QAAQ;;;;;EAKxB,eAAeC;;iBAGA;;WAEN,MAAM;;WAEN,YAAY,SAAS,eAAe;;;;;;;;;;;;;;wBAsB/B,iBACd,IAAI,cACJ,gBAAgBC,oBAChB,SAAS"}
|
package/dist/omp.mjs
CHANGED
package/dist/pi.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ToolDefinition as ToolDefinition$1 } from "./index.mjs";
|
|
2
2
|
import { ExtensionAPI, ToolDefinition } from "@earendil-works/pi-coding-agent";
|
|
3
|
-
interface PiToolOptions {
|
|
3
|
+
export interface PiToolOptions {
|
|
4
4
|
/**
|
|
5
5
|
* How a returned `isError` result reaches Pi.
|
|
6
6
|
*
|
|
@@ -14,7 +14,7 @@ interface PiToolOptions {
|
|
|
14
14
|
readonly renderers?: Readonly<Record<string, PiRenderers>>;
|
|
15
15
|
}
|
|
16
16
|
/** The host's own call and result renderers for one tool. */
|
|
17
|
-
type PiRenderers = Pick<ToolDefinition, "renderCall" | "renderResult">;
|
|
17
|
+
export type PiRenderers = Pick<ToolDefinition, "renderCall" | "renderResult">;
|
|
18
18
|
/**
|
|
19
19
|
* Registers every tool on the Pi extension API.
|
|
20
20
|
*
|
|
@@ -22,6 +22,5 @@ type PiRenderers = Pick<ToolDefinition, "renderCall" | "renderResult">;
|
|
|
22
22
|
* @param tools - Tools to register.
|
|
23
23
|
* @param options - Failure policy and renderers.
|
|
24
24
|
*/
|
|
25
|
-
declare function registerPiTools(pi: ExtensionAPI, tools: readonly ToolDefinition$1[], options?: PiToolOptions): void;
|
|
26
|
-
export { PiRenderers, PiToolOptions, registerPiTools };
|
|
25
|
+
export declare function registerPiTools(pi: ExtensionAPI, tools: readonly ToolDefinition$1[], options?: PiToolOptions): void;
|
|
27
26
|
//# sourceMappingURL=pi.d.mts.map
|
package/dist/pi.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pi.d.mts","names":["PiToolDefinition","ToolDefinition"],"sources":["../src/pi.ts"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"pi.d.mts","names":["PiToolDefinition","ToolDefinition"],"sources":["../src/pi.ts"],"mappings":";;iBAeiB;;;;;;;;;WASN;;WAEA,YAAY,SAAS,eAAe;;;YAInC,cAAc,KAAKA;;;;;;;;wBASf,gBACd,IAAI,cACJ,gBAAgBC,oBAChB,UAAS"}
|
package/dist/pi.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agntn/tools",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "One tool definition for MCP, Pi, OMP and the AI SDK",
|
|
5
5
|
"homepage": "https://github.com/agntn/tools#readme",
|
|
6
6
|
"bugs": "https://github.com/agntn/tools/issues",
|
|
@@ -35,37 +35,32 @@
|
|
|
35
35
|
"./ai": {
|
|
36
36
|
"types": "./dist/ai.d.mts",
|
|
37
37
|
"import": "./dist/ai.mjs"
|
|
38
|
+
},
|
|
39
|
+
"./cli": {
|
|
40
|
+
"types": "./dist/cli.d.mts",
|
|
41
|
+
"import": "./dist/cli.mjs"
|
|
38
42
|
}
|
|
39
43
|
},
|
|
40
44
|
"publishConfig": {
|
|
41
45
|
"access": "public"
|
|
42
46
|
},
|
|
43
|
-
"scripts": {
|
|
44
|
-
"build": "obuild",
|
|
45
|
-
"lint": "vp lint && vp fmt --check",
|
|
46
|
-
"lint:fix": "vp lint --fix && vp fmt",
|
|
47
|
-
"typecheck": "tsc --noEmit --skipLibCheck",
|
|
48
|
-
"test": "vp test run",
|
|
49
|
-
"test:watch": "vp test watch",
|
|
50
|
-
"release": "pnpm test && pnpm build && changelogen --release --push"
|
|
51
|
-
},
|
|
52
47
|
"devDependencies": {
|
|
53
48
|
"@agntn/ox": "0.1.0",
|
|
54
|
-
"@earendil-works/pi-coding-agent": "0.
|
|
49
|
+
"@earendil-works/pi-coding-agent": "1.0.1",
|
|
55
50
|
"@modelcontextprotocol/client": "2.2.0",
|
|
56
51
|
"@modelcontextprotocol/server": "2.2.0",
|
|
57
52
|
"@oh-my-pi/pi-coding-agent": "18.0.0",
|
|
58
53
|
"@types/node": "26.2.0",
|
|
59
|
-
"ai": "7.0.
|
|
54
|
+
"ai": "7.0.127",
|
|
60
55
|
"changelogen": "0.6.2",
|
|
61
|
-
"obuild": "0.4.
|
|
56
|
+
"obuild": "0.4.43",
|
|
62
57
|
"typebox": "1.3.34",
|
|
63
58
|
"typescript": "7.0.2",
|
|
64
|
-
"vite": "
|
|
65
|
-
"vite-plus": "
|
|
59
|
+
"vite": "npm:@voidzero-dev/vite-plus-core@1.0.0",
|
|
60
|
+
"vite-plus": "1.0.0"
|
|
66
61
|
},
|
|
67
62
|
"peerDependencies": {
|
|
68
|
-
"@earendil-works/pi-coding-agent": ">=0.84.2 <
|
|
63
|
+
"@earendil-works/pi-coding-agent": ">=0.84.2 <2",
|
|
69
64
|
"@modelcontextprotocol/server": ">=2.2.0 <3",
|
|
70
65
|
"@oh-my-pi/pi-coding-agent": ">=18.0.0 <19",
|
|
71
66
|
"ai": ">=7.0.0 <8"
|
|
@@ -87,5 +82,14 @@
|
|
|
87
82
|
"engines": {
|
|
88
83
|
"node": ">=24"
|
|
89
84
|
},
|
|
90
|
-
"
|
|
91
|
-
|
|
85
|
+
"scripts": {
|
|
86
|
+
"build": "obuild",
|
|
87
|
+
"lint": "vp lint && vp fmt --check",
|
|
88
|
+
"lint:fix": "vp lint --fix && vp fmt",
|
|
89
|
+
"typecheck": "tsc --noEmit --skipLibCheck",
|
|
90
|
+
"typecheck:dist": "tsc -p tsconfig.dist.json",
|
|
91
|
+
"test": "vp test run",
|
|
92
|
+
"test:watch": "vp test watch",
|
|
93
|
+
"release": "pnpm test && pnpm build && pnpm typecheck:dist && changelogen --release --push"
|
|
94
|
+
}
|
|
95
|
+
}
|
package/dist/index.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["Value.Check","Value.Errors"],"sources":["../src/index.ts"],"sourcesContent":["/**\n * One tool definition shared by every agent surface.\n *\n * A package declares each tool once with {@link defineTool}; the adapters in\n * `@agntn/tools/mcp`, `/pi`, `/omp` and `/ai` translate it into each host's\n * registration shape. The schema is plain TypeBox 1.x, which is plain JSON\n * Schema at runtime, so every host receives the same document.\n */\n\nimport type { Static, TObject } from \"typebox\";\n\n/**\n * TypeBox builders for tool schemas. Author schemas with this, not with a\n * bare `import { Type } from \"typebox\"`: OMP's extension loader rewrites the\n * bare `typebox` specifier, in the extension and every module it imports, to\n * its omptype facade, whose schemas are functions instead of JSON Schema.\n * Subpaths such as `typebox/type` are left alone.\n */\nexport * as Type from \"typebox/type\";\n\n/**\n * Every schema type of the same bundled TypeBox build. Import them from here, not from `typebox`.\n * All of them, not a few: a package that exports a tool definition needs each type its schema\n * uses to be nameable in its declarations.\n */\nexport type * from \"typebox\";\n\nimport { Value } from \"typebox/value\";\n\n/** Content block understood by MCP, Pi and OMP alike. */\nexport type ToolContent =\n | { type: \"text\"; text: string }\n | { type: \"image\"; data: string; mimeType: string };\n\n/** Text for the model plus details for the harness. */\nexport interface ToolResult<Details = unknown> {\n content: ToolContent[];\n details: Details;\n /** Set when the tool could not answer. Each adapter carries it to its host. */\n isError?: boolean;\n}\n\n/**\n * What a call does to the world, mapped to MCP annotations and OMP approval.\n *\n * - `read` changes nothing.\n * - `write` changes state that the next call can undo or overwrite.\n * - `destructive` deletes or overwrites what cannot be recovered.\n */\nexport type ToolEffect = \"read\" | \"write\" | \"destructive\";\n\n/** Per-call context the adapters hand to `execute`. */\nexport interface ToolCallContext {\n signal?: AbortSignal;\n}\n\nexport interface ToolDefinition<Input extends TObject = TObject, Details = unknown> {\n /** Wire name, `<package>_<operation>`. */\n readonly name: string;\n /** Human label: MCP `title`, Pi and OMP `label`. */\n readonly title: string;\n /** Complete instruction for the model. MCP clients see nothing else. */\n readonly description: string;\n /** Pi `promptSnippet`. */\n readonly snippet?: string;\n /** Pi `promptGuidelines`. Must not promise anything `description` lacks. */\n readonly guidelines?: readonly string[];\n readonly effect: ToolEffect;\n /** Repeating the call with the same input has no further effect. Defaults to `effect === \"read\"`. */\n readonly idempotent?: boolean;\n /** The call reaches outside the local machine. */\n readonly openWorld?: boolean;\n readonly input: Input;\n /**\n * Runs the tool on input that already passed {@link validateInput}.\n *\n * Method syntax on purpose: it keeps the parameter bivariant, so a list of\n * tools with different inputs is still a `readonly ToolDefinition[]`.\n */\n execute(\n input: Static<Input>,\n context: ToolCallContext,\n ): ToolResult<Details> | Promise<ToolResult<Details>>;\n}\n\n/** Thrown when a tool definition breaks a contract every surface relies on. */\nexport class ToolDefinitionError extends Error {\n override name = \"ToolDefinitionError\";\n}\n\n/** Thrown by {@link invokeTool} when the arguments fail the tool schema. */\nexport class ToolInputError extends Error {\n override name = \"ToolInputError\";\n /** One validation failure per line. Only these line breaks are the core's own. */\n readonly lines: readonly string[];\n\n /**\n * @param lines - One validation failure per line.\n */\n constructor(lines: readonly string[]) {\n super(lines.join(\"\\n\"));\n this.lines = lines;\n }\n}\n\nconst TOOL_NAME = /^[a-z][a-z0-9_]{0,63}$/;\n\n/**\n * Declares a tool and checks the schema rules every surface depends on.\n *\n * @param tool - Tool definition.\n * @returns {ToolDefinition<Input, Details>} The same definition, typed.\n */\nexport function defineTool<const Input extends TObject, Details>(\n tool: ToolDefinition<Input, Details>,\n): ToolDefinition<Input, Details> {\n if (!TOOL_NAME.test(tool.name)) {\n throw new ToolDefinitionError(`Tool name ${JSON.stringify(tool.name)} must match ${TOOL_NAME}`);\n }\n if (typeof tool.input !== \"object\" || tool.input === null) {\n // A function here is an omptype schema: `Type` came from a bare `typebox`\n // import that OMP remapped. `Value.Check` accepts any value against it.\n throw new ToolDefinitionError(\n `${tool.name}: input must be a JSON Schema object; build it with Type from @agntn/tools, not from \"typebox\"`,\n );\n }\n assertSchema(tool.name, wireSchema(tool));\n return tool;\n}\n\ntype SchemaNode = Readonly<Record<string, unknown>>;\n\n/**\n * Enforces two rules on the input schema, at every depth.\n *\n * A non-empty object must be closed (`additionalProperties: false`), because a\n * misspelled key would otherwise be dropped without a signal: `read_only`\n * instead of `readOnly` ran `harnesses_run` with full tool access. An empty\n * object stays open, since models send placeholders like `{_: \"\"}` to it.\n *\n * A union of literals must be `Type.Enum`: TypeBox serializes the union as\n * `anyOf` const objects, which triples the wire size, and `Value.Errors`\n * reports it as `must be equal to constant` against the first literal only.\n *\n * @param toolName - Tool the schema belongs to, for the error.\n * @param node - Schema node to check.\n * @param path - JSON pointer of the node, empty at the root.\n */\nfunction assertSchema(toolName: string, node: SchemaNode, path = \"\"): void {\n const at = path || \"/\";\n if (isOpenObject(node)) {\n throw new ToolDefinitionError(\n `${toolName}: object at ${at} must be closed with additionalProperties: false`,\n );\n }\n if (isLiteralUnion(node)) {\n throw new ToolDefinitionError(`${toolName}: union of literals at ${at} must use Type.Enum`);\n }\n for (const [child, childPath] of schemaChildren(node, path)) {\n assertSchema(toolName, child, childPath);\n }\n}\n\n/**\n * @param node - Schema node.\n * @returns {boolean} Whether the node is an object with properties that accepts other keys.\n */\nfunction isOpenObject(node: SchemaNode): boolean {\n const properties = node.properties as SchemaNode | undefined;\n return (\n node.type === \"object\" &&\n properties !== undefined &&\n Object.keys(properties).length > 0 &&\n node.additionalProperties !== false\n );\n}\n\n/**\n * @param node - Schema node.\n * @returns {boolean} Whether the node is an `anyOf` of two or more constants.\n */\nfunction isLiteralUnion(node: SchemaNode): boolean {\n const anyOf = node.anyOf as readonly SchemaNode[] | undefined;\n return anyOf !== undefined && anyOf.length > 1 && anyOf.every((branch) => \"const\" in branch);\n}\n\n/**\n * @param value - Any schema keyword value.\n * @returns {boolean} Whether it is a nested schema.\n */\nfunction isNode(value: unknown): value is SchemaNode {\n return typeof value === \"object\" && value !== null;\n}\n\n/**\n * The subschemas a value of this node can reach: properties, record values,\n * array items and union branches.\n *\n * @param node - Schema node.\n * @param path - JSON pointer of the node.\n * @returns {Array<[SchemaNode, string]>} Each subschema with its path.\n */\nfunction schemaChildren(node: SchemaNode, path: string): Array<[SchemaNode, string]> {\n const keyed = (keyword: string, childPath: (key: string) => string) =>\n Object.entries(isNode(node[keyword]) ? node[keyword] : {}).flatMap(\n ([key, child]): Array<[SchemaNode, string]> =>\n isNode(child) ? [[child, childPath(key)]] : [],\n );\n const branches = Array.isArray(node.anyOf) ? (node.anyOf as readonly unknown[]) : [];\n return [\n ...keyed(\"properties\", (key) => `${path}/${key}`),\n ...keyed(\"patternProperties\", () => `${path}/*`),\n ...(isNode(node.items) ? [[node.items, `${path}/items`] as [SchemaNode, string]] : []),\n ...branches.filter(isNode).map((branch): [SchemaNode, string] => [branch, path]),\n ];\n}\n\n/**\n * The input schema as the plain JSON Schema object every host receives.\n *\n * TypeBox 1.x schemas are plain objects already; this only drops the static\n * type, which lacks the index signature host APIs declare.\n *\n * @param tool - Tool whose schema to emit.\n * @returns {Record<string, unknown>} JSON Schema document.\n */\nexport function wireSchema(tool: ToolDefinition): Record<string, unknown> {\n return Object.fromEntries(Object.entries(tool.input));\n}\n\n/**\n * Indexes tools by name.\n *\n * A `Map`, not a plain object: a lookup of `toString` in a `Record` finds\n * `Object.prototype.toString` and skips the unknown-tool branch.\n *\n * @param tools - Tools to index.\n * @returns {ReadonlyMap<string, ToolDefinition>} Tools by wire name.\n */\nexport function indexTools(tools: readonly ToolDefinition[]): ReadonlyMap<string, ToolDefinition> {\n const byName = new Map<string, ToolDefinition>();\n for (const tool of tools) {\n if (byName.has(tool.name)) throw new ToolDefinitionError(`Duplicate tool name ${tool.name}`);\n byName.set(tool.name, tool);\n }\n return byName;\n}\n\nexport type InputCheck<Input extends TObject> =\n | { ok: true; value: Static<Input> }\n | { ok: false; lines: readonly string[] };\n\n/**\n * Validates arguments against the tool schema, reporting every failure.\n *\n * Runs on every surface, not only MCP: a host may skip its own validation, and\n * OMP's omptype drops `pattern` from the schema it emits. The message has one\n * line per failure: an undeclared key names itself with the keys the tool\n * takes, and an enum failure names the allowed values, so the caller does not\n * go back to the tool list and guess. Format from agntn/hashes (#58).\n *\n * @param tool - Tool whose schema applies.\n * @param args - Arguments as received from the host.\n * @returns {InputCheck<Input>} The typed value, or the failures, one per line.\n */\nexport function validateInput<Input extends TObject>(\n tool: ToolDefinition<Input, unknown>,\n args: unknown,\n): InputCheck<Input> {\n if (Value.Check(tool.input, args)) return { ok: true, value: args };\n\n const declared = Object.keys(tool.input.properties);\n const unknownKeys =\n args !== null && typeof args === \"object\" && !Array.isArray(args)\n ? Object.keys(args).filter((key) => !declared.includes(key))\n : [];\n // A closed schema reports each undeclared key again, as `schema is false` at its path.\n const reported = new Set(\n unknownKeys.map((key) => `/${key.replaceAll(\"~\", \"~0\").replaceAll(\"/\", \"~1\")}`),\n );\n const lines = [\n ...unknownKeys.map(\n (key) =>\n `Invalid arguments: unknown property ${JSON.stringify(key)}; takes ${declared.join(\", \")}`,\n ),\n ...Value.Errors(tool.input, args)\n .filter(\n (error) => error.keyword !== \"additionalProperties\" && !reported.has(error.instancePath),\n )\n .map((error) => {\n const allowed =\n error.keyword === \"enum\"\n ? (error.params as { allowedValues?: unknown }).allowedValues\n : undefined;\n const message = Array.isArray(allowed)\n ? `must be one of ${allowed.join(\", \")}`\n : error.message;\n return `Invalid arguments at ${error.instancePath || \"/\"}: ${message}`;\n }),\n ];\n return { ok: false, lines: lines.length > 0 ? [...new Set(lines)] : [\"Invalid arguments\"] };\n}\n\n/**\n * Validates and runs a tool. Every adapter calls through here.\n *\n * @param tool - Tool to run.\n * @param args - Arguments as received from the host.\n * @param context - Per-call context.\n * @returns {Promise<ToolResult>} The executor's result, unchanged.\n * @throws {ToolInputError} When the arguments fail the schema.\n */\nexport async function invokeTool(\n tool: ToolDefinition,\n args: unknown,\n context: ToolCallContext = {},\n): Promise<ToolResult> {\n const checked = validateInput(tool, args);\n if (!checked.ok) throw new ToolInputError(checked.lines);\n return await tool.execute(checked.value, context);\n}\n\nconst LINE_BREAKING = /[\\p{Cc}\\p{Cf}\\p{Zl}\\p{Zp}]/gu;\n\n/**\n * Terminal escape sequences, the pattern Node 26 uses in `stripVTControlCharacters`.\n * Kept here rather than imported from `node:util` so the core runs in a browser or a worker.\n */\nconst ESCAPE_SEQUENCE =\n /* oxlint-disable-next-line no-control-regex */\n /(?:\\u001B\\][\\s\\S]*?(?:\\u0007|\\u001B\\u005C|\\u009C))|[\\u001B\\u009B][[\\]()#;?]*(?:\\d{1,4}(?:[;:]\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]/g;\n\n/**\n * Makes a value safe for one line of terminal or protocol text.\n *\n * Removes escape sequences, then replaces every control, format, line and\n * paragraph separator character with a space: a raw newline, U+2028 or a bidi\n * override (U+202E, a `Cf`) in an echoed value forges a line that reads as the\n * tool's own output. `String()` first, since hostile JSON ignores declared types.\n *\n * @param value - Value to render.\n * @returns {string} Single-line text.\n */\nexport function sanitizeLine(value: unknown): string {\n return String(value)\n .replaceAll(ESCAPE_SEQUENCE, \"\")\n .replaceAll(LINE_BREAKING, \" \")\n .replaceAll(/ {2,}/g, \" \")\n .trim();\n}\n\n/**\n * Text of a result, for hosts that carry failures as thrown errors.\n *\n * @param result - Tool result.\n * @returns {string} Text blocks joined by newlines.\n */\nexport function resultText(result: ToolResult): string {\n return result.content.flatMap((block) => (block.type === \"text\" ? [block.text] : [])).join(\"\\n\");\n}\n"],"mappings":";AAsFA,IAAa,sBAAb,cAAyC,MAAM;CAC7C,OAAgB;AAClB;AAGA,IAAa,iBAAb,cAAoC,MAAM;CACxC,OAAgB;CAEhB;;;EAKA,KAAA,QAAY;CACV;AACA;AACF,MAAA,YAAA;AAGF,SAAM,WAAY,MAAA;;;;;;AAQlB,SAAgB,aACd,UACgC,MAAA,OAAA,IAAA;CAChC,MAAK,KAAA,QAAU;CAGf,IAAI,aAAY,IAAA,GAAA,MAAU,IAAA,oBAA2B,GAAA,SAG7C,cAAI,GAAA,iDACK;CAGjB,IAAA,eAAkB,IAAA,GAAM,MAAA,IAAW,oBAAK,GAAA,SAAA,yBAAA,GAAA,oBAAA;CACxC,KAAA,MAAO,CAAA,OAAA,cAAA,eAAA,MAAA,IAAA,GAAA,aAAA,UAAA,OAAA,SAAA;AACT;;;;;;;;;;;;;CAoBA,MAAA,SAAS,SAAa,cAAoC,OAAO,QAAU,OAAA,KAAA,QAAA,IAAA,KAAA,WAAA,CAAA,CAAA,CAAA,CAAA,SAAA,CAAA,KAAA,WAAA,OAAA,KAAA,IAAA,CAAA,CAAA,OAAA,UAAA,GAAA,CAAA,CAAA,IAAA,CAAA,CAAA;CACzE,MAAM,WAAK,MAAQ,QAAA,KAAA,KAAA,IAAA,KAAA,QAAA,CAAA;CACnB,OAAI;EAKJ,GAAI,MAAA,eAAmB,QACf,GAAI,KAAA,GAAA,KAAA;EAEZ,GAAA,MAAK,2BAA4B,GAAA,KAAA,GAAe;EAGlD,GAAA,OAAA,KAAA,KAAA,IAAA,CAAA,CAAA,KAAA,OAAA,GAAA,KAAA,OAAA,CAAA,IAAA,CAAA;;;;AAMA,SAAS,WAAA,MAAa;CACpB,OAAM,OAAA,YAAkB,OAAA,QAAA,KAAA,KAAA,CAAA;AACxB;;;;;EAYF,OAAS,IAAA,KAAA,MAAe,IAAA;CACtB;CACA,OAAO;AACT;;;;EAMA,OAAS;CACP;CACF,MAAA,WAAA,OAAA,KAAA,KAAA,MAAA,UAAA;;;;;;;;;EAUA,IAAA;EACE,OAAM,MAAA,SAAS,IAAiB,CAAA,GAAA,IAAA,IAC9B,KAAA,CAAO,IAAA,CAAA,mBAAoB;CAI7B;AACA;AAEE,eAAS,WAAA,MAAA,MAA2B,UAAQ,CAAG,GAAA;CAC/C,MAAI,UAAY,cAAW,MAAK,IAAO;CACvC,IAAG,CAAA,QAAS,IAAA,MAAO,IAAO,eAAM,QAAkC,KAAQ;CAC5E,OAAA,MAAA,KAAA,QAAA,QAAA,OAAA,OAAA;AACF;;;;;;;CAWA,OAAA,OAAgB,QAAW,SAA+C,UAAA,MAAA,SAAA,SAAA,CAAA,MAAA,IAAA,IAAA,CAAA,CAAA,CAAA,CAAA,KAAA,IAAA;AACxE"}
|