@codeworksh/plugin 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/{event-6sTQ_4bq.d.mts → event-CmzS4aGe.d.mts} +328 -23
- package/event.d.mts +2 -2
- package/event.mjs +15 -3
- package/event.mjs.map +1 -1
- package/{ids-CHjmAdTc.d.mts → ids-CpPeP5Ks.d.mts} +11 -3
- package/ids.d.mts +2 -2
- package/ids.mjs +7 -2
- package/ids.mjs.map +1 -1
- package/index.d.mts +2 -2
- package/index.mjs +1 -1
- package/mcp-DEWhnBQw.d.mts +122 -0
- package/package.json +7 -2
- package/plugin/mcp.d.mts +2 -0
- package/plugin/mcp.mjs +7 -0
- package/plugin/mcp.mjs.map +1 -0
- package/plugin/section.mjs +1 -0
- package/plugin/section.mjs.map +1 -1
- package/plugin/tool.d.mts +1 -1
- package/plugin/tool.mjs +2 -1
- package/plugin/tool.mjs.map +1 -1
- package/{plugin-XaYYRsX-.mjs → plugin-C3Qy4-Yx.mjs} +9 -3
- package/plugin-C3Qy4-Yx.mjs.map +1 -0
- package/{plugin-Dcv5TWNr.d.mts → plugin-aMOw2zJZ.d.mts} +23 -14
- package/plugin.d.mts +4 -3
- package/plugin.mjs +3 -2
- package/schema.d.mts +2 -0
- package/schema.mjs +3 -1
- package/schema.mjs.map +1 -1
- package/{settings-DGYWREuu.d.mts → settings-CxiAtEXT.d.mts} +22 -2
- package/settings.d.mts +2 -2
- package/settings.mjs +4 -0
- package/settings.mjs.map +1 -1
- package/tool/progress.d.mts +1 -1
- package/{tool-_ajVYIY5.d.mts → tool-C7gcMoga.d.mts} +33 -3
- package/{tool-D4_I_rzy.d.mts → tool-C9TzQ9nG.d.mts} +10 -10
- package/tool.d.mts +2 -2
- package/tool.mjs +49 -3
- package/tool.mjs.map +1 -1
- package/plugin-XaYYRsX-.mjs.map +0 -1
package/settings.mjs
CHANGED
package/settings.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"settings.mjs","names":["AikitModel"],"sources":["../../src/settings.ts"],"sourcesContent":["import { Model as AikitModel, type Protocol } from \"@codeworksh/aikit\";\nimport { Effect, Schema, type SchemaAST, SchemaGetter, SchemaIssue } from \"effect\";\nimport { isAikitModelInfo, NonNegativeInt, validateAikitModelInfo } from \"./schema.ts\";\n\nexport const ThinkingLevel = Schema.Literals(Object.values(AikitModel.ThinkingLevelEnum));\nexport const ToolExecution = Schema.Literals([\"sequential\", \"parallel\"]);\nexport type ToolExecution = typeof ToolExecution.Type;\nconst Budgets = Schema.Record(\n\tSchema.Literals(Object.values(AikitModel.ThinkingLevelEnum).filter((level) => level !== \"off\")),\n\tSchema.optional(Schema.Finite),\n);\n\n/** Aikit does not export its request schema; keep this routing surface checked against its public types. */\nexport const requestFields = {\n\ttemperature: Schema.optional(Schema.Finite),\n\tmaxTokens: Schema.optional(Schema.Finite),\n\tcacheRetention: Schema.optional(Schema.Literals([\"none\", \"short\", \"long\"])),\n\theaders: Schema.optional(Schema.Record(Schema.String, Schema.String)),\n\ttimeoutMs: Schema.optional(Schema.Finite),\n\tidleTimeoutMs: Schema.optional(Schema.Finite),\n\tmaxRetries: Schema.optional(Schema.Finite),\n\tmetadata: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),\n\tthinkingBudgets: Schema.optional(Budgets),\n\tbaseURL: Schema.optional(Schema.String),\n\tmethod: Schema.optional(Schema.Literals(Object.values(AikitModel.APIMethodEnum))),\n} satisfies Record<\n\t| Exclude<keyof Protocol.CommonOptions, \"signal\" | \"sessionId\" | \"reasoning\" | \"apiKey\" | \"onPayload\">\n\t| \"baseURL\"\n\t| \"method\",\n\tSchema.Top\n>;\n\n/**\n * An API key named, never written: `\"${NAME}\"`, read from the host process environment when the\n * model is called. Settings only ever hold the variable's name.\n */\nconst keyReference = /^\\$\\{([A-Za-z_][A-Za-z0-9_]*)\\}$/;\nconst keyReferenceError = 'apiKey must reference an environment variable, e.g. \"${OPENAI_API_KEY}\"';\nexport const KeyReference = Schema.String.check(\n\tSchema.makeFilter((value) => keyReference.test(value) || keyReferenceError),\n);\n\n/** The variable a `\"${NAME}\"` reference names. */\nexport const keyName = (reference: string): string => keyReference.exec(reference)?.[1] ?? reference;\n\nconst reserved = new Set([\n\t\"toolChoice\",\n\t\"activeTools\",\n\t\"provider\",\n\t\"id\",\n\t\"signal\",\n\t\"sessionId\",\n\t\"reasoning\",\n\t\"modelId\",\n\t\"onPayload\",\n\t\"api\",\n\t\"npm\",\n\t\"providerOptionsKey\",\n\t\"compat\",\n\t\"thinkingLevelMap\",\n]);\n\n/** The wire protocol a model speaks, which a catalog entry may have wrong for a local endpoint. */\nexport const ModelProtocol = Schema.Literals(Object.values(AikitModel.KnownProviderEnum));\n\nexport const Block = Schema.StructWithRest(\n\tSchema.Struct({\n\t\t...requestFields,\n\t\tprotocol: Schema.optional(ModelProtocol),\n\t\tthinkingLevel: Schema.optional(ThinkingLevel),\n\t\ttoolExecution: Schema.optional(ToolExecution),\n\t\tcontextWindow: Schema.optional(Schema.Finite),\n\t\t/** Which environment variable holds the key for this model: `\"${NAME}\"`. */\n\t\tapiKey: Schema.optional(KeyReference),\n\t\textras: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),\n\t}),\n\t[Schema.Record(Schema.String, Schema.Unknown)],\n).check(\n\tSchema.makeFilter(\n\t\t(value) => Object.keys(value).every((key) => !reserved.has(key)) || \"Reserved configuration key in model options\",\n\t),\n);\nexport type Block = typeof Block.Type;\n\nexport const Model = Schema.Struct({\n\tprovider: Schema.optional(Schema.String),\n\tid: Schema.optional(Schema.String),\n\tthinkingLevel: Schema.optional(ThinkingLevel),\n\ttoolExecution: Schema.optional(ToolExecution),\n\tthinkingBudgets: Schema.optional(Budgets),\n\toptions: Schema.optional(Block),\n\tproviderOptions: Schema.optional(Schema.Record(Schema.String, Schema.Record(Schema.String, Block))),\n});\nconst reasonOf = (cause: unknown): string => (cause instanceof Error ? cause.message : String(cause));\n\nconst decodeModelEntry = (value: unknown, options: SchemaAST.ParseOptions) =>\n\tEffect.try({\n\t\ttry: () => {\n\t\t\tconst entry = validateAikitModelInfo(value, \"models entry\");\n\t\t\tif (entry.provider.key !== undefined && !keyReference.test(entry.provider.key)) {\n\t\t\t\tthrow new Error(`models entry ${entry.provider.id}/${entry.id}: provider.key: ${keyReferenceError}`);\n\t\t\t}\n\t\t\treturn entry;\n\t\t},\n\t\tcatch: (cause) => new SchemaIssue.InvalidValue({ message: reasonOf(cause) }, value, options),\n\t});\n\n/**\n * A catalog entry in settings: an aikit `Model.Info`, read exactly like an entry of the generated\n * catalog. The one difference is `provider.key`, which must be a `\"${NAME}\"` reference.\n */\nexport const ModelEntry = Schema.Unknown.pipe(\n\tSchema.decodeTo(Schema.declare<AikitModel.Info>(isAikitModelInfo, { expected: \"aikit Model.Info\" }), {\n\t\tdecode: SchemaGetter.transformEffect(decodeModelEntry),\n\t\tencode: SchemaGetter.transformEffect(decodeModelEntry),\n\t}),\n);\nexport type ModelEntry = typeof ModelEntry.Type;\n\n/** A module to load: a path, a `file:` URL, or a package spec. */\nconst PluginReference = Schema.String.check(Schema.isNonEmpty());\n/**\n * Configuration for a plugin something else already selected, named by its ID (`plugin`) or by\n * its registered module string (`package`). It never loads anything: an entry naming a plugin\n * that is not in the selection is ignored.\n */\nconst config = {\n\tenabled: Schema.optional(Schema.Boolean),\n\toptions: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),\n};\nexport const PluginPatch = Schema.Union(\n\t[Schema.Struct({ plugin: PluginReference, ...config }), Schema.Struct({ package: PluginReference, ...config })],\n\t// `oneOf`, so an entry carrying both keys is a decode failure rather than one of them being\n\t// quietly dropped -- naming a plugin two ways at once says two different things.\n\t{ mode: \"oneOf\" },\n);\nexport const PluginEntry = Schema.Union([PluginReference, PluginPatch]);\nexport type PluginEntry = typeof PluginEntry.Type;\n\n/**\n * Agent-level retry of a turn whose provider request failed transiently (rate limit, overload,\n * 5xx, dropped connection). Delays double from `baseDelayMs` and stop growing at `maxDelayMs`;\n * a server that asks for a longer wait than `maxDelayMs` is not retried. `maxRetries: 0` is off.\n *\n * Separate from `model.options.maxRetries`, which retries inside the provider SDK and defaults to\n * 0 so that the two do not multiply, and so a quota error reaches the loop instead of being retried.\n */\nexport const Retry = Schema.Struct({\n\tmaxRetries: Schema.optional(NonNegativeInt),\n\tbaseDelayMs: Schema.optional(NonNegativeInt),\n\tmaxDelayMs: Schema.optional(NonNegativeInt),\n});\nexport interface RetryPolicy {\n\treadonly maxRetries: number;\n\treadonly baseDelayMs: number;\n\treadonly maxDelayMs: number;\n}\n\nexport const Patch = Schema.Struct({\n\t$schema: Schema.optional(Schema.String),\n\tplugins: Schema.optional(Schema.Array(PluginEntry)),\n\tmodel: Schema.optional(Model),\n\tmodels: Schema.optional(Schema.Array(ModelEntry)),\n\tretry: Schema.optional(Retry),\n});\nexport type Patch = typeof Patch.Type;\n\n/**\n * One plugin entry, and where it came from.\n *\n * Flattening every layer's `plugins` into one array loses the file that declared each entry, and\n * that cannot be recovered afterwards: two layers may declare the same string, so attribution is\n * genuinely gone rather than merely inconvenient. Three things need it -- anchoring a relative\n * path, naming the declaring layer in `plugin list`, and the missing-plugin diagnostic -- so the\n * loaded shape carries it from the start.\n *\n * In simple terms:\n * `written` - is what module the developer is declaring - what\n * `file` - where the module is being declared - where\n * `entry` - the resolved path of the module, relative to the `file`; especially needed for local.\n *\n * Example:\n * written: \"@acme/x@^1\"\n * entry: \"@acme/x@^1\"\n * file: \"/Users/me/.codework/settings.jsonc\"\n *\n * written: \"./plugins/mine.mjs\"\n * entry: \"/Users/me/.codework/plugins/mine.mjs\"\n * file: \"/Users/me/.codework/settings.jsonc\"\n */\nexport interface Declared {\n\t/** The entry exactly as the file spells it, which is the string a person will search for. */\n\treadonly written: PluginEntry;\n\t/** The same entry with any relative path anchored to the directory of its declaring file. */\n\treadonly entry: PluginEntry;\n\t/** The settings file that declared it. */\n\treadonly file: string;\n}\n\n/** A `models` entry, and the settings file that declared it. */\nexport interface DeclaredModel {\n\treadonly entry: AikitModel.Info;\n\treadonly file: string;\n}\n\nexport interface Info {\n\t/**\n\t * Plugin entries added to the harness selection, in order: every layer's entries, lowest\n\t * priority first, so a project's list extends the user's rather than replacing it.\n\t *\n\t * Anchored, and stripped of provenance: this is the list the loader consumes. {@link Info.declared}\n\t * is the same list with the file each entry came from.\n\t */\n\treadonly plugins: ReadonlyArray<PluginEntry>;\n\t/** {@link Info.plugins}, with the origin of each entry. Same order, same length. */\n\treadonly declared: ReadonlyArray<Declared>;\n\t/**\n\t * Catalog entries from every layer, lowest priority first. Applied over the generated catalog\n\t * in this order, so for one `provider.id` + `id` the last entry wins.\n\t */\n\treadonly models: ReadonlyArray<DeclaredModel>;\n\treadonly model: typeof Model.Type & {\n\t\treadonly provider: string;\n\t\treadonly id: string;\n\t\treadonly thinkingLevel: AikitModel.ThinkingLevel;\n\t\treadonly toolExecution: ToolExecution;\n\t};\n\treadonly retry: RetryPolicy;\n}\n\n/** Let aikit supply model-aware generation defaults. */\nexport const defaults: Info = {\n\tplugins: [],\n\tdeclared: [],\n\tmodels: [],\n\tmodel: {\n\t\tprovider: \"openai\",\n\t\tid: \"gpt-5.6-luna\",\n\t\tthinkingLevel: \"medium\",\n\t\ttoolExecution: \"sequential\",\n\t\toptions: { timeoutMs: 3_600_000, idleTimeoutMs: 300_000, maxRetries: 0 },\n\t},\n\tretry: { maxRetries: 3, baseDelayMs: 2_000, maxDelayMs: 60_000 },\n};\n"],"mappings":";;;;AAIA,MAAa,gBAAgB,OAAO,SAAS,OAAO,OAAOA,QAAW,iBAAiB,CAAC;AACxF,MAAa,gBAAgB,OAAO,SAAS,CAAC,cAAc,UAAU,CAAC;AAEvE,MAAM,UAAU,OAAO,OACtB,OAAO,SAAS,OAAO,OAAOA,QAAW,iBAAiB,CAAC,CAAC,QAAQ,UAAU,UAAU,KAAK,CAAC,GAC9F,OAAO,SAAS,OAAO,MAAM,CAC9B;;AAGA,MAAa,gB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AAM,SAAS;CACd,SAAS,OAAO,SAAS,OAAO,OAAO;CACvC,SAAS,OAAO,SAAS,OAAO,OAAO,OAAO,QAAQ,OAAO,OAAO,CAAC;AACtE;AACA,MAAa,cAAc,OAAO,MACjC,CAAC,OAAO,OAAO;CAAE,QAAQ;CAAiB,GAAG;AAAO,CAAC,GAAG,OAAO,OAAO;CAAE,SAAS;CAAiB,GAAG;AAAO,CAAC,CAAC,GAG9G,EAAE,MAAM,QAAQ,CACjB;AACA,MAAa,cAAc,OAAO,MAAM,CAAC,iBAAiB,WAAW,CAAC;;;;;;;;;AAWtE,MAAa,QAAQ,OAAO,OAAO;CAClC,YAAY,OAAO,SAAS,cAAc;CAC1C,aAAa,OAAO,SAAS,cAAc;CAC3C,YAAY,OAAO,SAAS,cAAc;AAC3C,CAAC;AAOD,MAAa,QAAQ,OAAO,OAAO;CAClC,SAAS,OAAO,SAAS,OAAO,MAAM;CACtC,SAAS,OAAO,SAAS,OAAO,MAAM,WAAW,CAAC;CAClD,OAAO,OAAO,SAAS,KAAK;CAC5B,QAAQ,OAAO,SAAS,OAAO,MAAM,UAAU,CAAC;CAChD,OAAO,OAAO,SAAS,KAAK;AAC7B,CAAC;;AAmED,MAAa,WAAiB;CAC7B,SAAS,CAAC;CACV,UAAU,CAAC;CACX,QAAQ,CAAC;CACT,OAAO;EACN,UAAU;EACV,IAAI;EACJ,eAAe;EACf,eAAe;EACf,SAAS;GAAE,WAAW;GAAW,eAAe;GAAS,YAAY;EAAE;CACxE;CACA,OAAO;EAAE,YAAY;EAAG,aAAa;EAAO,YAAY;CAAO;AAChE"}
|
|
1
|
+
{"version":3,"file":"settings.mjs","names":["AikitModel"],"sources":["../../src/settings.ts"],"sourcesContent":["import { Model as AikitModel, type Protocol } from \"@codeworksh/aikit\";\nimport { Effect, Schema, type SchemaAST, SchemaGetter, SchemaIssue } from \"effect\";\nimport type { ServerConfig } from \"./plugin/mcp.ts\";\nimport { isAikitModelInfo, NonNegativeInt, validateAikitModelInfo } from \"./schema.ts\";\n\nexport const ThinkingLevel = Schema.Literals(Object.values(AikitModel.ThinkingLevelEnum));\nexport const ToolExecution = Schema.Literals([\"sequential\", \"parallel\"]);\nexport type ToolExecution = typeof ToolExecution.Type;\nconst Budgets = Schema.Record(\n\tSchema.Literals(Object.values(AikitModel.ThinkingLevelEnum).filter((level) => level !== \"off\")),\n\tSchema.optional(Schema.Finite),\n);\n\n/** Aikit does not export its request schema; keep this routing surface checked against its public types. */\nexport const requestFields = {\n\ttemperature: Schema.optional(Schema.Finite),\n\tmaxTokens: Schema.optional(Schema.Finite),\n\tcacheRetention: Schema.optional(Schema.Literals([\"none\", \"short\", \"long\"])),\n\theaders: Schema.optional(Schema.Record(Schema.String, Schema.String)),\n\ttimeoutMs: Schema.optional(Schema.Finite),\n\tidleTimeoutMs: Schema.optional(Schema.Finite),\n\tmaxRetries: Schema.optional(Schema.Finite),\n\tmetadata: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),\n\tthinkingBudgets: Schema.optional(Budgets),\n\tbaseURL: Schema.optional(Schema.String),\n\tmethod: Schema.optional(Schema.Literals(Object.values(AikitModel.APIMethodEnum))),\n} satisfies Record<\n\t| Exclude<keyof Protocol.CommonOptions, \"signal\" | \"sessionId\" | \"reasoning\" | \"apiKey\" | \"onPayload\">\n\t| \"baseURL\"\n\t| \"method\",\n\tSchema.Top\n>;\n\n/**\n * An API key named, never written: `\"${NAME}\"`, read from the host process environment when the\n * model is called. Settings only ever hold the variable's name.\n */\nconst keyReference = /^\\$\\{([A-Za-z_][A-Za-z0-9_]*)\\}$/;\nconst keyReferenceError = 'apiKey must reference an environment variable, e.g. \"${OPENAI_API_KEY}\"';\nexport const KeyReference = Schema.String.check(\n\tSchema.makeFilter((value) => keyReference.test(value) || keyReferenceError),\n);\n\n/** The variable a `\"${NAME}\"` reference names. */\nexport const keyName = (reference: string): string => keyReference.exec(reference)?.[1] ?? reference;\n\nconst reserved = new Set([\n\t\"toolChoice\",\n\t\"activeTools\",\n\t\"provider\",\n\t\"id\",\n\t\"signal\",\n\t\"sessionId\",\n\t\"reasoning\",\n\t\"modelId\",\n\t\"onPayload\",\n\t\"api\",\n\t\"npm\",\n\t\"providerOptionsKey\",\n\t\"compat\",\n\t\"thinkingLevelMap\",\n]);\n\n/** The wire protocol a model speaks, which a catalog entry may have wrong for a local endpoint. */\nexport const ModelProtocol = Schema.Literals(Object.values(AikitModel.KnownProviderEnum));\n\nexport const Block = Schema.StructWithRest(\n\tSchema.Struct({\n\t\t...requestFields,\n\t\tprotocol: Schema.optional(ModelProtocol),\n\t\tthinkingLevel: Schema.optional(ThinkingLevel),\n\t\ttoolExecution: Schema.optional(ToolExecution),\n\t\tcontextWindow: Schema.optional(Schema.Finite),\n\t\t/** Which environment variable holds the key for this model: `\"${NAME}\"`. */\n\t\tapiKey: Schema.optional(KeyReference),\n\t\textras: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),\n\t}),\n\t[Schema.Record(Schema.String, Schema.Unknown)],\n).check(\n\tSchema.makeFilter(\n\t\t(value) => Object.keys(value).every((key) => !reserved.has(key)) || \"Reserved configuration key in model options\",\n\t),\n);\nexport type Block = typeof Block.Type;\n\nexport const Model = Schema.Struct({\n\tprovider: Schema.optional(Schema.String),\n\tid: Schema.optional(Schema.String),\n\tthinkingLevel: Schema.optional(ThinkingLevel),\n\ttoolExecution: Schema.optional(ToolExecution),\n\tthinkingBudgets: Schema.optional(Budgets),\n\toptions: Schema.optional(Block),\n\tproviderOptions: Schema.optional(Schema.Record(Schema.String, Schema.Record(Schema.String, Block))),\n});\nconst reasonOf = (cause: unknown): string => (cause instanceof Error ? cause.message : String(cause));\n\nconst decodeModelEntry = (value: unknown, options: SchemaAST.ParseOptions) =>\n\tEffect.try({\n\t\ttry: () => {\n\t\t\tconst entry = validateAikitModelInfo(value, \"models entry\");\n\t\t\tif (entry.provider.key !== undefined && !keyReference.test(entry.provider.key)) {\n\t\t\t\tthrow new Error(`models entry ${entry.provider.id}/${entry.id}: provider.key: ${keyReferenceError}`);\n\t\t\t}\n\t\t\treturn entry;\n\t\t},\n\t\tcatch: (cause) => new SchemaIssue.InvalidValue({ message: reasonOf(cause) }, value, options),\n\t});\n\n/**\n * A catalog entry in settings: an aikit `Model.Info`, read exactly like an entry of the generated\n * catalog. The one difference is `provider.key`, which must be a `\"${NAME}\"` reference.\n */\nexport const ModelEntry = Schema.Unknown.pipe(\n\tSchema.decodeTo(Schema.declare<AikitModel.Info>(isAikitModelInfo, { expected: \"aikit Model.Info\" }), {\n\t\tdecode: SchemaGetter.transformEffect(decodeModelEntry),\n\t\tencode: SchemaGetter.transformEffect(decodeModelEntry),\n\t}),\n);\nexport type ModelEntry = typeof ModelEntry.Type;\n\n/** A module to load: a path, a `file:` URL, or a package spec. */\nconst PluginReference = Schema.String.check(Schema.isNonEmpty());\n/**\n * Configuration for a plugin something else already selected, named by its ID (`plugin`) or by\n * its registered module string (`package`). It never loads anything: an entry naming a plugin\n * that is not in the selection is ignored.\n */\nconst config = {\n\tenabled: Schema.optional(Schema.Boolean),\n\toptions: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),\n};\nexport const PluginPatch = Schema.Union(\n\t[Schema.Struct({ plugin: PluginReference, ...config }), Schema.Struct({ package: PluginReference, ...config })],\n\t// `oneOf`, so an entry carrying both keys is a decode failure rather than one of them being\n\t// quietly dropped -- naming a plugin two ways at once says two different things.\n\t{ mode: \"oneOf\" },\n);\nexport const PluginEntry = Schema.Union([PluginReference, PluginPatch]);\nexport type PluginEntry = typeof PluginEntry.Type;\n\n/**\n * Agent-level retry of a turn whose provider request failed transiently (rate limit, overload,\n * 5xx, dropped connection). Delays double from `baseDelayMs` and stop growing at `maxDelayMs`;\n * a server that asks for a longer wait than `maxDelayMs` is not retried. `maxRetries: 0` is off.\n *\n * Separate from `model.options.maxRetries`, which retries inside the provider SDK and defaults to\n * 0 so that the two do not multiply, and so a quota error reaches the loop instead of being retried.\n */\nexport const Retry = Schema.Struct({\n\tmaxRetries: Schema.optional(NonNegativeInt),\n\tbaseDelayMs: Schema.optional(NonNegativeInt),\n\tmaxDelayMs: Schema.optional(NonNegativeInt),\n});\nexport interface RetryPolicy {\n\treadonly maxRetries: number;\n\treadonly baseDelayMs: number;\n\treadonly maxDelayMs: number;\n}\n\nexport const Patch = Schema.Struct({\n\t$schema: Schema.optional(Schema.String),\n\tplugins: Schema.optional(Schema.Array(PluginEntry)),\n\tmodel: Schema.optional(Model),\n\tmodels: Schema.optional(Schema.Array(ModelEntry)),\n\tretry: Schema.optional(Retry),\n});\nexport type Patch = typeof Patch.Type;\n\n/**\n * One plugin entry, and where it came from.\n *\n * Flattening every layer's `plugins` into one array loses the file that declared each entry, and\n * that cannot be recovered afterwards: two layers may declare the same string, so attribution is\n * genuinely gone rather than merely inconvenient. Three things need it -- anchoring a relative\n * path, naming the declaring layer in `plugin list`, and the missing-plugin diagnostic -- so the\n * loaded shape carries it from the start.\n *\n * In simple terms:\n * `written` - is what module the developer is declaring - what\n * `file` - where the module is being declared - where\n * `entry` - the resolved path of the module, relative to the `file`; especially needed for local.\n *\n * Example:\n * written: \"@acme/x@^1\"\n * entry: \"@acme/x@^1\"\n * file: \"/Users/me/.codework/settings.jsonc\"\n *\n * written: \"./plugins/mine.mjs\"\n * entry: \"/Users/me/.codework/plugins/mine.mjs\"\n * file: \"/Users/me/.codework/settings.jsonc\"\n */\nexport interface Declared {\n\t/** The entry exactly as the file spells it, which is the string a person will search for. */\n\treadonly written: PluginEntry;\n\t/** The same entry with any relative path anchored to the directory of its declaring file. */\n\treadonly entry: PluginEntry;\n\t/** The settings file that declared it. */\n\treadonly file: string;\n}\n\n/** A `models` entry, and the settings file that declared it. */\nexport interface DeclaredModel {\n\treadonly entry: AikitModel.Info;\n\treadonly file: string;\n}\n\n/** One server from an `mcp.json`, and the file that defined it. */\nexport interface McpServer {\n\treadonly name: string;\n\treadonly config: ServerConfig;\n\treadonly file: string;\n\t/** The project `mcp.json` whose entry overrides this user server's `enabled` or exposure. */\n\treadonly override?: string;\n}\n\n/** The `mcp.json` layers: the user file, then the project's, whose entries replace same-named ones. */\nexport interface McpSettings {\n\treadonly servers: ReadonlyArray<McpServer>;\n\t/** Files and entries that could not be used. Each is skipped; everything else still loads. */\n\treadonly errors: ReadonlyArray<string>;\n}\n\nexport interface Info {\n\t/**\n\t * Plugin entries added to the harness selection, in order: every layer's entries, lowest\n\t * priority first, so a project's list extends the user's rather than replacing it.\n\t *\n\t * Anchored, and stripped of provenance: this is the list the loader consumes. {@link Info.declared}\n\t * is the same list with the file each entry came from.\n\t */\n\treadonly plugins: ReadonlyArray<PluginEntry>;\n\t/** {@link Info.plugins}, with the origin of each entry. Same order, same length. */\n\treadonly declared: ReadonlyArray<Declared>;\n\t/**\n\t * Catalog entries from every layer, lowest priority first. Applied over the generated catalog\n\t * in this order, so for one `provider.id` + `id` the last entry wins.\n\t */\n\treadonly models: ReadonlyArray<DeclaredModel>;\n\treadonly model: typeof Model.Type & {\n\t\treadonly provider: string;\n\t\treadonly id: string;\n\t\treadonly thinkingLevel: AikitModel.ThinkingLevel;\n\t\treadonly toolExecution: ToolExecution;\n\t};\n\treadonly retry: RetryPolicy;\n\treadonly mcp: McpSettings;\n}\n\n/** Let aikit supply model-aware generation defaults. */\nexport const defaults: Info = {\n\tplugins: [],\n\tdeclared: [],\n\tmodels: [],\n\tmodel: {\n\t\tprovider: \"openai\",\n\t\tid: \"gpt-5.6-luna\",\n\t\tthinkingLevel: \"medium\",\n\t\ttoolExecution: \"sequential\",\n\t\toptions: { timeoutMs: 3_600_000, idleTimeoutMs: 300_000, maxRetries: 0 },\n\t},\n\tretry: { maxRetries: 3, baseDelayMs: 2_000, maxDelayMs: 60_000 },\n\tmcp: { servers: [], errors: [] },\n};\n"],"mappings":";;;;AAKA,MAAa,gBAAgB,OAAO,SAAS,OAAO,OAAOA,QAAW,iBAAiB,CAAC;AACxF,MAAa,gBAAgB,OAAO,SAAS,CAAC,cAAc,UAAU,CAAC;AAEvE,MAAM,UAAU,O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2 +1,2 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { C as ToolProgressPartial, S as ToolProgress, T as noop, w as make, x as IToolProgress } from "../tool-C7gcMoga.mjs";
|
|
2
2
|
export { IToolProgress, ToolProgress, ToolProgressPartial, make, noop };
|
|
@@ -26,7 +26,7 @@ declare const make$1: (report: IToolProgress["report"]) => Layer.Layer<ToolProgr
|
|
|
26
26
|
/** Drops every update — the default until the executor wires a live event sink. */
|
|
27
27
|
declare const noop: Layer.Layer<ToolProgress>;
|
|
28
28
|
declare namespace tool_d_exports {
|
|
29
|
-
export { AnyToolDef, AnyToolImpl, Handler, ModelContent, RegisteredTool, ToolCallContext, ToolDef, ToolImpl, define, implement, make, provide, register, toAikitTool, toProviderJsonSchema };
|
|
29
|
+
export { AnyToolDef, AnyToolImpl, Handler, ModelContent, RegisteredTool, ToolCallContext, ToolDef, ToolExposure, ToolImpl, declared, define, fromJsonSchema, implement, isFromJsonSchema, make, provide, register, toAikitTool, toProviderJsonSchema };
|
|
30
30
|
}
|
|
31
31
|
/**
|
|
32
32
|
* The tool definition + handler model.
|
|
@@ -50,8 +50,21 @@ declare const ToolCallContext: Schema.Struct<{
|
|
|
50
50
|
readonly callID: Schema.String;
|
|
51
51
|
readonly toolName: Schema.String;
|
|
52
52
|
readonly rawArgs: Schema.$Record<Schema.String, Schema.Unknown>;
|
|
53
|
+
/** Input modalities of the model the call answers, e.g. `["text", "image"]`. */
|
|
54
|
+
readonly modelInput: Schema.optional<Schema.$Array<Schema.Literals<readonly ["text", "image"]>>>;
|
|
53
55
|
}>;
|
|
54
56
|
type ToolCallContext = typeof ToolCallContext.Type;
|
|
57
|
+
/**
|
|
58
|
+
* Where a tool is reachable. `direct` and `model` tools are declared to the model each turn;
|
|
59
|
+
* `model` ones are never callable from other tools. `codemode` and `deferred` tools stay off the
|
|
60
|
+
* wire until loaded, and `hidden` ones never reach the model.
|
|
61
|
+
*/
|
|
62
|
+
declare const ToolExposure: Schema.Literals<readonly ["direct", "model", "codemode", "deferred", "hidden"]>;
|
|
63
|
+
type ToolExposure = typeof ToolExposure.Type;
|
|
64
|
+
/** Whether a tool is declared to the model every turn. Omitted exposure means `direct`. */
|
|
65
|
+
declare const declared: (def: {
|
|
66
|
+
readonly exposure?: ToolExposure;
|
|
67
|
+
}) => boolean;
|
|
55
68
|
/**
|
|
56
69
|
* A pure tool definition. Parametrised over the *schema* instances so the
|
|
57
70
|
* decoded parameter/success/failure types can be recovered via `["Type"]`.
|
|
@@ -68,6 +81,8 @@ interface ToolDef<Name extends string = string, Params extends Schema.Top = Sche
|
|
|
68
81
|
readonly promptSnippet?: string;
|
|
69
82
|
/** Optional guideline bullets appended to the default system prompt Guidelines section when this tool is active. */
|
|
70
83
|
readonly promptGuidelines?: ReadonlyArray<string>;
|
|
84
|
+
/** Where the tool is reachable. Omit → `direct`. */
|
|
85
|
+
readonly exposure?: ToolExposure;
|
|
71
86
|
/**
|
|
72
87
|
* Repair argument shapes models commonly send before they are validated against
|
|
73
88
|
* `parameters`. Return a copy; a throw makes the arguments invalid.
|
|
@@ -107,6 +122,7 @@ interface DefineInput<Name extends string, Params extends Schema.Top, Success ex
|
|
|
107
122
|
readonly label?: string;
|
|
108
123
|
readonly promptSnippet?: string;
|
|
109
124
|
readonly promptGuidelines?: ReadonlyArray<string>;
|
|
125
|
+
readonly exposure?: ToolExposure;
|
|
110
126
|
readonly prepareArguments?: (args: unknown) => unknown;
|
|
111
127
|
readonly parameters: Params;
|
|
112
128
|
readonly constrainedSampling?: Message.Tool["constrainedSampling"];
|
|
@@ -144,6 +160,20 @@ declare const register: <Name extends string, Params extends Schema.Top, Success
|
|
|
144
160
|
* registry never has to unify anyone's `R`.
|
|
145
161
|
*/
|
|
146
162
|
declare const provide: <Name extends string, Params extends Schema.Top, Success extends Schema.Top, Failure extends Schema.Top, R>(impl: ToolImpl<Name, Params, Success, Failure, R | ToolProgress>, layer: Layer.Layer<R>) => RegisteredTool;
|
|
163
|
+
/**
|
|
164
|
+
* Parameters from a JSON Schema someone else wrote, such as an MCP server's `inputSchema`. The
|
|
165
|
+
* provider receives it exactly as written; arguments are validated against its Effect translation,
|
|
166
|
+
* `pattern`s included: the user chose the server. A schema the translation cannot express (an
|
|
167
|
+
* external `$ref`, a pattern invalid in Unicode mode) validates nothing, since rejecting arguments
|
|
168
|
+
* the schema allows would be worse than letting the server check them.
|
|
169
|
+
*/
|
|
170
|
+
declare const fromJsonSchema: (schema: Record<string, unknown>) => Schema.Top;
|
|
171
|
+
/**
|
|
172
|
+
* Whether `schema` came from {@link fromJsonSchema}. Its arguments are checked as JSON Schema checks
|
|
173
|
+
* them: a key a closed object does not declare is an error, not dropped, since the tool receives the
|
|
174
|
+
* arguments as written.
|
|
175
|
+
*/
|
|
176
|
+
declare const isFromJsonSchema: (schema: Schema.Top) => boolean;
|
|
147
177
|
/**
|
|
148
178
|
* Derive a provider-safe JSON Schema object from an Effect Schema. This is the
|
|
149
179
|
* single boundary that crosses into the provider wire; if a provider rejects a
|
|
@@ -157,5 +187,5 @@ declare const toProviderJsonSchema: (schema: Schema.Top) => Record<string, unkno
|
|
|
157
187
|
*/
|
|
158
188
|
declare const toAikitTool: (def: AnyToolDef) => Message.Tool;
|
|
159
189
|
//#endregion
|
|
160
|
-
export {
|
|
161
|
-
//# sourceMappingURL=tool-
|
|
190
|
+
export { ToolProgressPartial as C, ToolProgress as S, noop as T, register as _, RegisteredTool as a, tool_d_exports as b, ToolExposure as c, define as d, fromJsonSchema as f, provide as g, make as h, ModelContent as i, ToolImpl as l, isFromJsonSchema as m, AnyToolImpl as n, ToolCallContext as o, implement as p, Handler as r, ToolDef as s, AnyToolDef as t, declared as u, toAikitTool as v, make$1 as w, IToolProgress as x, toProviderJsonSchema as y };
|
|
191
|
+
//# sourceMappingURL=tool-C7gcMoga.d.mts.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as RegisteredTool, i as ModelContent, t as AnyToolDef } from "./tool-
|
|
1
|
+
import { a as RegisteredTool, i as ModelContent, t as AnyToolDef } from "./tool-C7gcMoga.mjs";
|
|
2
2
|
import { Effect, Schema } from "effect";
|
|
3
3
|
declare namespace tool_d_exports {
|
|
4
4
|
export { HookReturn, ToolAddOptions, ToolAfter, ToolAfterFn, ToolAfterResult, ToolBefore, ToolBeforeFn, ToolBeforeResult, ToolDefPatch, ToolRegistration, ToolRegistry, ToolResultContent };
|
|
@@ -7,10 +7,14 @@ declare const ToolBefore: Schema.Struct<{
|
|
|
7
7
|
readonly callID: Schema.String;
|
|
8
8
|
readonly toolName: Schema.String;
|
|
9
9
|
readonly rawArgs: Schema.$Record<Schema.String, Schema.Unknown>;
|
|
10
|
+
readonly modelInput: Schema.optional<Schema.$Array<Schema.Literals<readonly ["text", "image"]>>>;
|
|
10
11
|
readonly sessionId: Schema.brand<Schema.String, "Session.ID"> & {
|
|
11
12
|
ascending: (id?: string) => string & import("effect/Brand").Brand<"Session.ID">;
|
|
12
13
|
create: () => string & import("effect/Brand").Brand<"Session.ID">;
|
|
13
14
|
};
|
|
15
|
+
readonly threadId: Schema.brand<Schema.String, "Thread.ID"> & {
|
|
16
|
+
create: () => string & import("effect/Brand").Brand<"Thread.ID">;
|
|
17
|
+
};
|
|
14
18
|
readonly messageId: Schema.brand<Schema.String, "Message.ID"> & {
|
|
15
19
|
create: () => string & import("effect/Brand").Brand<"Message.ID">;
|
|
16
20
|
from: (id: string) => string & import("effect/Brand").Brand<"Message.ID">;
|
|
@@ -22,17 +26,20 @@ declare const ToolAfter: Schema.Struct<{
|
|
|
22
26
|
readonly callID: Schema.String;
|
|
23
27
|
readonly toolName: Schema.String;
|
|
24
28
|
readonly rawArgs: Schema.$Record<Schema.String, Schema.Unknown>;
|
|
29
|
+
readonly modelInput: Schema.optional<Schema.$Array<Schema.Literals<readonly ["text", "image"]>>>;
|
|
25
30
|
readonly sessionId: Schema.brand<Schema.String, "Session.ID"> & {
|
|
26
31
|
ascending: (id?: string) => string & import("effect/Brand").Brand<"Session.ID">;
|
|
27
32
|
create: () => string & import("effect/Brand").Brand<"Session.ID">;
|
|
28
33
|
};
|
|
34
|
+
readonly threadId: Schema.brand<Schema.String, "Thread.ID"> & {
|
|
35
|
+
create: () => string & import("effect/Brand").Brand<"Thread.ID">;
|
|
36
|
+
};
|
|
29
37
|
readonly messageId: Schema.brand<Schema.String, "Message.ID"> & {
|
|
30
38
|
create: () => string & import("effect/Brand").Brand<"Message.ID">;
|
|
31
39
|
from: (id: string) => string & import("effect/Brand").Brand<"Message.ID">;
|
|
32
40
|
};
|
|
33
41
|
readonly params: Schema.Unknown;
|
|
34
42
|
readonly terminal: Schema.decodeTo<Schema.declare<{
|
|
35
|
-
addedToolNames?: string[];
|
|
36
43
|
arguments: Record<string, any>;
|
|
37
44
|
callID: string;
|
|
38
45
|
name: string;
|
|
@@ -58,7 +65,6 @@ declare const ToolAfter: Schema.Struct<{
|
|
|
58
65
|
};
|
|
59
66
|
type: "toolCall";
|
|
60
67
|
} | {
|
|
61
|
-
addedToolNames?: string[];
|
|
62
68
|
arguments: Record<string, any>;
|
|
63
69
|
callID: string;
|
|
64
70
|
name: string;
|
|
@@ -84,7 +90,6 @@ declare const ToolAfter: Schema.Struct<{
|
|
|
84
90
|
};
|
|
85
91
|
type: "toolCall";
|
|
86
92
|
} | {
|
|
87
|
-
addedToolNames?: string[];
|
|
88
93
|
arguments: Record<string, any>;
|
|
89
94
|
callID: string;
|
|
90
95
|
name: string;
|
|
@@ -110,7 +115,6 @@ declare const ToolAfter: Schema.Struct<{
|
|
|
110
115
|
};
|
|
111
116
|
type: "toolCall";
|
|
112
117
|
} | {
|
|
113
|
-
addedToolNames?: string[];
|
|
114
118
|
arguments: Record<string, any>;
|
|
115
119
|
callID: string;
|
|
116
120
|
name: string;
|
|
@@ -136,7 +140,6 @@ declare const ToolAfter: Schema.Struct<{
|
|
|
136
140
|
};
|
|
137
141
|
type: "toolCall";
|
|
138
142
|
}, {
|
|
139
|
-
addedToolNames?: string[];
|
|
140
143
|
arguments: Record<string, any>;
|
|
141
144
|
callID: string;
|
|
142
145
|
name: string;
|
|
@@ -162,7 +165,6 @@ declare const ToolAfter: Schema.Struct<{
|
|
|
162
165
|
};
|
|
163
166
|
type: "toolCall";
|
|
164
167
|
} | {
|
|
165
|
-
addedToolNames?: string[];
|
|
166
168
|
arguments: Record<string, any>;
|
|
167
169
|
callID: string;
|
|
168
170
|
name: string;
|
|
@@ -188,7 +190,6 @@ declare const ToolAfter: Schema.Struct<{
|
|
|
188
190
|
};
|
|
189
191
|
type: "toolCall";
|
|
190
192
|
} | {
|
|
191
|
-
addedToolNames?: string[];
|
|
192
193
|
arguments: Record<string, any>;
|
|
193
194
|
callID: string;
|
|
194
195
|
name: string;
|
|
@@ -214,7 +215,6 @@ declare const ToolAfter: Schema.Struct<{
|
|
|
214
215
|
};
|
|
215
216
|
type: "toolCall";
|
|
216
217
|
} | {
|
|
217
|
-
addedToolNames?: string[];
|
|
218
218
|
arguments: Record<string, any>;
|
|
219
219
|
callID: string;
|
|
220
220
|
name: string;
|
|
@@ -284,4 +284,4 @@ interface ToolRegistry {
|
|
|
284
284
|
}
|
|
285
285
|
//#endregion
|
|
286
286
|
export { ToolAfterResult as a, ToolBeforeResult as c, ToolRegistry as d, ToolResultContent as f, ToolAfterFn as i, ToolDefPatch as l, ToolAddOptions as n, ToolBefore as o, tool_d_exports as p, ToolAfter as r, ToolBeforeFn as s, HookReturn as t, ToolRegistration as u };
|
|
287
|
-
//# sourceMappingURL=tool-
|
|
287
|
+
//# sourceMappingURL=tool-C9TzQ9nG.d.mts.map
|
package/tool.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as RegisteredTool, c as
|
|
2
|
-
export { AnyToolDef, AnyToolImpl, Handler, ModelContent, RegisteredTool, ToolCallContext, ToolDef, ToolImpl, define, implement, make, provide, register, toAikitTool, toProviderJsonSchema };
|
|
1
|
+
import { _ as register, a as RegisteredTool, c as ToolExposure, d as define, f as fromJsonSchema, g as provide, h as make, i as ModelContent, l as ToolImpl, m as isFromJsonSchema, n as AnyToolImpl, o as ToolCallContext, p as implement, r as Handler, s as ToolDef, t as AnyToolDef, u as declared, v as toAikitTool, y as toProviderJsonSchema } from "./tool-C7gcMoga.mjs";
|
|
2
|
+
export { AnyToolDef, AnyToolImpl, Handler, ModelContent, RegisteredTool, ToolCallContext, ToolDef, ToolExposure, ToolImpl, declared, define, fromJsonSchema, implement, isFromJsonSchema, make, provide, register, toAikitTool, toProviderJsonSchema };
|
package/tool.mjs
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
|
|
2
2
|
import { ToolExecutionError } from "./tool/error.mjs";
|
|
3
|
-
import { Effect, Schema, SchemaAST } from "effect";
|
|
3
|
+
import { Effect, JsonSchema, Schema, SchemaAST, SchemaRepresentation } from "effect";
|
|
4
4
|
//#region src/tool.ts
|
|
5
5
|
var tool_exports = /* @__PURE__ */ __exportAll({
|
|
6
6
|
ToolCallContext: () => ToolCallContext,
|
|
7
|
+
ToolExposure: () => ToolExposure,
|
|
8
|
+
declared: () => declared,
|
|
7
9
|
define: () => define,
|
|
10
|
+
fromJsonSchema: () => fromJsonSchema,
|
|
8
11
|
implement: () => implement,
|
|
12
|
+
isFromJsonSchema: () => isFromJsonSchema,
|
|
9
13
|
make: () => make,
|
|
10
14
|
provide: () => provide,
|
|
11
15
|
register: () => register,
|
|
@@ -16,8 +20,24 @@ var tool_exports = /* @__PURE__ */ __exportAll({
|
|
|
16
20
|
const ToolCallContext = Schema.Struct({
|
|
17
21
|
callID: Schema.String,
|
|
18
22
|
toolName: Schema.String,
|
|
19
|
-
rawArgs: Schema.Record(Schema.String, Schema.Unknown)
|
|
23
|
+
rawArgs: Schema.Record(Schema.String, Schema.Unknown),
|
|
24
|
+
/** Input modalities of the model the call answers, e.g. `["text", "image"]`. */
|
|
25
|
+
modelInput: Schema.optional(Schema.Array(Schema.Literals(["text", "image"])))
|
|
20
26
|
});
|
|
27
|
+
/**
|
|
28
|
+
* Where a tool is reachable. `direct` and `model` tools are declared to the model each turn;
|
|
29
|
+
* `model` ones are never callable from other tools. `codemode` and `deferred` tools stay off the
|
|
30
|
+
* wire until loaded, and `hidden` ones never reach the model.
|
|
31
|
+
*/
|
|
32
|
+
const ToolExposure = Schema.Literals([
|
|
33
|
+
"direct",
|
|
34
|
+
"model",
|
|
35
|
+
"codemode",
|
|
36
|
+
"deferred",
|
|
37
|
+
"hidden"
|
|
38
|
+
]);
|
|
39
|
+
/** Whether a tool is declared to the model every turn. Omitted exposure means `direct`. */
|
|
40
|
+
const declared = (def) => def.exposure === void 0 || def.exposure === "direct" || def.exposure === "model";
|
|
21
41
|
/** Define a pure tool (handler attached later via {@link implement} or a toolkit). */
|
|
22
42
|
const define = (input) => ({ ...input });
|
|
23
43
|
/** Attach a handler to an existing definition (the testable def/exec split). */
|
|
@@ -49,12 +69,38 @@ const register = (impl) => toRegistered(impl.definition, impl.handler);
|
|
|
49
69
|
* registry never has to unify anyone's `R`.
|
|
50
70
|
*/
|
|
51
71
|
const provide = (impl, layer) => toRegistered(impl.definition, ((params, ctx) => impl.handler(params, ctx).pipe(Effect.provide(layer))));
|
|
72
|
+
const providerJsonSchema = "codework/providerJsonSchema";
|
|
73
|
+
/**
|
|
74
|
+
* Parameters from a JSON Schema someone else wrote, such as an MCP server's `inputSchema`. The
|
|
75
|
+
* provider receives it exactly as written; arguments are validated against its Effect translation,
|
|
76
|
+
* `pattern`s included: the user chose the server. A schema the translation cannot express (an
|
|
77
|
+
* external `$ref`, a pattern invalid in Unicode mode) validates nothing, since rejecting arguments
|
|
78
|
+
* the schema allows would be worse than letting the server check them.
|
|
79
|
+
*/
|
|
80
|
+
const fromJsonSchema = (schema) => {
|
|
81
|
+
return (() => {
|
|
82
|
+
try {
|
|
83
|
+
const draft07 = typeof schema.$schema === "string" && schema.$schema.includes("draft-07") || "definitions" in schema;
|
|
84
|
+
return SchemaRepresentation.fromJsonSchemaDocument(draft07 ? JsonSchema.fromSchemaDraft07(schema) : JsonSchema.fromSchemaDraft2020_12(schema), { patterns: "apply" });
|
|
85
|
+
} catch {
|
|
86
|
+
return Schema.Unknown;
|
|
87
|
+
}
|
|
88
|
+
})().annotate({ [providerJsonSchema]: schema });
|
|
89
|
+
};
|
|
90
|
+
/**
|
|
91
|
+
* Whether `schema` came from {@link fromJsonSchema}. Its arguments are checked as JSON Schema checks
|
|
92
|
+
* them: a key a closed object does not declare is an error, not dropped, since the tool receives the
|
|
93
|
+
* arguments as written.
|
|
94
|
+
*/
|
|
95
|
+
const isFromJsonSchema = (schema) => SchemaAST.resolveAt(providerJsonSchema)(schema.ast) !== void 0;
|
|
52
96
|
/**
|
|
53
97
|
* Derive a provider-safe JSON Schema object from an Effect Schema. This is the
|
|
54
98
|
* single boundary that crosses into the provider wire; if a provider rejects a
|
|
55
99
|
* construct, fix it here. Draft-07 inlines the root (no top-level `$ref`).
|
|
56
100
|
*/
|
|
57
101
|
const toProviderJsonSchema = (schema) => {
|
|
102
|
+
const written = SchemaAST.resolveAt(providerJsonSchema)(schema.ast);
|
|
103
|
+
if (written !== void 0) return written;
|
|
58
104
|
const encoded = SchemaAST.toEncoded(schema.ast);
|
|
59
105
|
if (SchemaAST.isObjects(encoded) && encoded.propertySignatures.length === 0 && encoded.indexSignatures.length === 0) return {
|
|
60
106
|
type: "object",
|
|
@@ -75,6 +121,6 @@ const toAikitTool = (def) => ({
|
|
|
75
121
|
...def.constrainedSampling === void 0 ? {} : { constrainedSampling: def.constrainedSampling }
|
|
76
122
|
});
|
|
77
123
|
//#endregion
|
|
78
|
-
export { ToolCallContext, define, implement, make, provide, register, tool_exports as t, toAikitTool, toProviderJsonSchema };
|
|
124
|
+
export { ToolCallContext, ToolExposure, declared, define, fromJsonSchema, implement, isFromJsonSchema, make, provide, register, tool_exports as t, toAikitTool, toProviderJsonSchema };
|
|
79
125
|
|
|
80
126
|
//# sourceMappingURL=tool.mjs.map
|
package/tool.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool.mjs","names":[],"sources":["../../src/tool.ts"],"sourcesContent":["import type { Message } from \"@codeworksh/aikit\";\nimport { Effect, type Layer, Schema, SchemaAST } from \"effect\";\nimport type { TSchema } from \"typebox\";\nimport { ToolExecutionError } from \"./tool/error.ts\";\nimport type { ToolProgress } from \"./tool/progress.ts\";\n\n/**\n * The tool definition + handler model.\n *\n * A tool definition is pure, serializable data: name, description, and Effect\n * Schema for parameters / success / failure. Execution is a separate `Handler`\n * — an `Effect` whose capability dependencies (e.g. `ToolShell`) live in its\n * requirements `R`, provided by a Layer at runtime. Separating the two is the\n * main testing win: assert on the definition as plain data, and run the handler\n * against a stub capability Layer.\n *\n * Effect Schema is the single source of truth. {@link toAikitTool} derives a\n * provider-safe JSON Schema object for the aikit wire view; the harness\n * decode/encodes arguments and results with Effect Schema natively (it does not\n * use aikit's Typebox validators).\n */\n\n/** What the model reads next turn (the `content` side of content/details). */\nexport type ModelContent = ReadonlyArray<Message.TextContent | Message.ImageContent>;\n\n/** Per-call metadata handed to a handler instead of positional args. */\nexport const ToolCallContext = Schema.Struct({\n\tcallID: Schema.String,\n\ttoolName: Schema.String,\n\trawArgs: Schema.Record(Schema.String, Schema.Unknown),\n});\nexport type ToolCallContext = typeof ToolCallContext.Type;\n\n/**\n * A pure tool definition. Parametrised over the *schema* instances so the\n * decoded parameter/success/failure types can be recovered via `[\"Type\"]`.\n */\nexport interface ToolDef<\n\tName extends string = string,\n\tParams extends Schema.Top = Schema.Top,\n\tSuccess extends Schema.Top = Schema.Top,\n\tFailure extends Schema.Top = Schema.Top,\n> {\n\treadonly name: Name;\n\treadonly description: string;\n\t/** Human-readable display label (kept from the previous `AgentTool`). */\n\treadonly label?: string;\n\t/**\n\t * A short one-line summary for compact tool listings (e.g. a system-prompt tool index),\n\t * distinct from the fuller `description`.\n\t */\n\treadonly promptSnippet?: string;\n\t/** Optional guideline bullets appended to the default system prompt Guidelines section when this tool is active. */\n\treadonly promptGuidelines?: ReadonlyArray<string>;\n\t/**\n\t * Repair argument shapes models commonly send before they are validated against\n\t * `parameters`. Return a copy; a throw makes the arguments invalid.\n\t */\n\treadonly prepareArguments?: (args: unknown) => unknown;\n\treadonly parameters: Params;\n\t/**\n\t * How the provider constrains the generated arguments. `{ type: \"json_schema\", strict: \"prefer\" }` sends\n\t * `parameters` in strict mode where the provider can express it and falls back to non-strict otherwise.\n\t */\n\treadonly constrainedSampling?: Message.Tool[\"constrainedSampling\"];\n\treadonly success: Success;\n\t/** Declared, model-visible failures (typed). Omit for tools that cannot fail expectedly. */\n\treadonly failure?: Failure;\n\t/** Render success for the model. Omit → executor falls back to JSON text. */\n\treadonly encodeContent?: (success: Success[\"Type\"]) => ModelContent;\n\t/** Render an expected failure for the model. Omit → executor falls back to JSON text. */\n\treadonly encodeFailureContent?: (failure: Failure[\"Type\"]) => ModelContent;\n\t/**\n\t * The `details` kept with a success, for UIs and programmatic consumers. Omit → the encoded\n\t * success. Set it when `encodeContent` already carries the payload, so it is not stored twice.\n\t */\n\treadonly encodeDetails?: (success: Success[\"Type\"]) => unknown;\n}\n\n/** A handler: validated params + context → typed success or typed failure. */\nexport type Handler<Params extends Schema.Top, Success extends Schema.Top, Failure extends Schema.Top, R = never> = (\n\tparams: Params[\"Type\"],\n\tctx: ToolCallContext,\n) => Effect.Effect<Success[\"Type\"], Failure[\"Type\"], R>;\n\n/** A definition paired with its handler (the unit the executor runs). */\nexport interface ToolImpl<\n\tName extends string = string,\n\tParams extends Schema.Top = Schema.Top,\n\tSuccess extends Schema.Top = Schema.Top,\n\tFailure extends Schema.Top = Schema.Top,\n\tR = never,\n> {\n\treadonly definition: ToolDef<Name, Params, Success, Failure>;\n\treadonly handler: Handler<Params, Success, Failure, R>;\n}\n\n// Heterogeneous-collection aliases. `any` for the schema generics keeps handlers\n// of differing parameter types assignable into one array (the precise generics\n// live on the authoring helpers below).\n// biome-ignore lint/suspicious/noExplicitAny: erased schema generics for storage\nexport type AnyToolDef = ToolDef<string, any, any, any>;\n// biome-ignore lint/suspicious/noExplicitAny: erased schema generics for storage\nexport type AnyToolImpl<R = never> = ToolImpl<string, any, any, any, R>;\n\ninterface DefineInput<\n\tName extends string,\n\tParams extends Schema.Top,\n\tSuccess extends Schema.Top,\n\tFailure extends Schema.Top,\n> {\n\treadonly name: Name;\n\treadonly description: string;\n\treadonly label?: string;\n\treadonly promptSnippet?: string;\n\treadonly promptGuidelines?: ReadonlyArray<string>;\n\treadonly prepareArguments?: (args: unknown) => unknown;\n\treadonly parameters: Params;\n\treadonly constrainedSampling?: Message.Tool[\"constrainedSampling\"];\n\treadonly success: Success;\n\treadonly failure?: Failure;\n\treadonly encodeContent?: (success: Success[\"Type\"]) => ModelContent;\n\treadonly encodeFailureContent?: (failure: Failure[\"Type\"]) => ModelContent;\n\treadonly encodeDetails?: (success: Success[\"Type\"]) => unknown;\n}\n\n/** Define a pure tool (handler attached later via {@link implement} or a toolkit). */\nexport const define = <\n\tName extends string,\n\tParams extends Schema.Top,\n\tSuccess extends Schema.Top,\n\tFailure extends Schema.Top = Schema.Top,\n>(\n\tinput: DefineInput<Name, Params, Success, Failure>,\n): ToolDef<Name, Params, Success, Failure> => ({\n\t...input,\n});\n\n/** Attach a handler to an existing definition (the testable def/exec split). */\nexport const implement = <\n\tName extends string,\n\tParams extends Schema.Top,\n\tSuccess extends Schema.Top,\n\tFailure extends Schema.Top,\n\tR = never,\n>(\n\tdefinition: ToolDef<Name, Params, Success, Failure>,\n\thandler: Handler<Params, Success, Failure, R>,\n): ToolImpl<Name, Params, Success, Failure, R> => ({ definition, handler });\n\n/** Sugar for the co-located case: a definition with its handler in one object. */\nexport const make = <\n\tName extends string,\n\tParams extends Schema.Top,\n\tSuccess extends Schema.Top,\n\tFailure extends Schema.Top = Schema.Top,\n\tR = never,\n>(\n\tinput: DefineInput<Name, Params, Success, Failure> & {\n\t\treadonly handler: Handler<Params, Success, Failure, R>;\n\t},\n): ToolImpl<Name, Params, Success, Failure, R> => {\n\tconst { handler, ...rest } = input;\n\treturn { definition: define(rest), handler };\n};\n\n/**\n * A tool ready to register: its capability requirements have been discharged, leaving only\n * the executor-provided {@link ToolProgress}. The registry and executor hold `RegisteredTool`s\n * and are non-generic (only `handle` is generic, over a progress sink's `RProgress`), so any\n * number of tools — built-in or\n * third-party/plugin — compose without a shared capability union\n */\nexport interface RegisteredTool {\n\treadonly definition: AnyToolDef;\n\treadonly handler: (\n\t\tparams: unknown,\n\t\tctx: ToolCallContext,\n\t) => Effect.Effect<unknown, ToolExecutionError, ToolProgress>;\n}\n\nconst toRegistered = <\n\tName extends string,\n\tParams extends Schema.Top,\n\tSuccess extends Schema.Top,\n\tFailure extends Schema.Top,\n>(\n\tdefinition: ToolDef<Name, Params, Success, Failure>,\n\thandler: Handler<Params, Success, Failure, ToolProgress>,\n): RegisteredTool => ({\n\tdefinition,\n\t// The executor decodes with `definition.parameters` before invoking this\n\t// erased handler, so restoring the authored parameter type is safe here.\n\thandler: (params, ctx) =>\n\t\thandler(params as Params[\"Type\"], ctx).pipe(\n\t\t\tEffect.mapError((cause) => new ToolExecutionError({ toolName: definition.name, cause })),\n\t\t),\n});\n\n/** Register a tool whose only requirement is the executor-provided progress service. */\nexport const register = <\n\tName extends string,\n\tParams extends Schema.Top,\n\tSuccess extends Schema.Top,\n\tFailure extends Schema.Top,\n>(\n\timpl: ToolImpl<Name, Params, Success, Failure, ToolProgress>,\n): RegisteredTool => toRegistered(impl.definition, impl.handler);\n\n/**\n * Discharge a tool's capability requirements into a {@link RegisteredTool}, erasing its `R`\n * (the executor still provides `ToolProgress`). This is the registration boundary: a\n * plugin/third-party tool provides its own fully-resolved capability Layer here, so the\n * registry never has to unify anyone's `R`.\n */\nexport const provide = <\n\tName extends string,\n\tParams extends Schema.Top,\n\tSuccess extends Schema.Top,\n\tFailure extends Schema.Top,\n\tR,\n>(\n\timpl: ToolImpl<Name, Params, Success, Failure, R | ToolProgress>,\n\tlayer: Layer.Layer<R>,\n): RegisteredTool =>\n\t// `Effect.provide` discharges `R`, leaving `ToolProgress`. TS can't simplify\n\t// `Exclude<ToolProgress, R>` for a generic `R`, so localize the cast before\n\t// crossing the registered-tool boundary.\n\ttoRegistered(impl.definition, ((params, ctx) => impl.handler(params, ctx).pipe(Effect.provide(layer))) as Handler<\n\t\tParams,\n\t\tSuccess,\n\t\tFailure,\n\t\tToolProgress\n\t>);\n\n/**\n * Derive a provider-safe JSON Schema object from an Effect Schema. This is the\n * single boundary that crosses into the provider wire; if a provider rejects a\n * construct, fix it here. Draft-07 inlines the root (no top-level `$ref`).\n */\nexport const toProviderJsonSchema = (schema: Schema.Top): Record<string, unknown> => {\n\t// Effect reads `Struct({})` as TS `{}` (any non-null) and emits `{ not: { type: \"null\" } }`;\n\t// providers require an object, so emit one shaped like a non-empty struct's.\n\tconst encoded = SchemaAST.toEncoded(schema.ast);\n\tif (\n\t\tSchemaAST.isObjects(encoded) &&\n\t\tencoded.propertySignatures.length === 0 &&\n\t\tencoded.indexSignatures.length === 0\n\t) {\n\t\treturn { type: \"object\", properties: {}, additionalProperties: true };\n\t}\n\treturn Schema.toStandardJSONSchemaV1(schema)[\"~standard\"].jsonSchema.input({ target: \"draft-07\" });\n};\n\n/**\n * Build the aikit `Message.Tool` wire view from a definition. The derived JSON\n * Schema object satisfies aikit's `parameters` slot structurally at runtime; the\n * single localized cast keeps aikit untouched (decision 3-A).\n */\nexport const toAikitTool = (def: AnyToolDef): Message.Tool => ({\n\tname: def.name,\n\tdescription: def.description,\n\tparameters: toProviderJsonSchema(def.parameters) as unknown as TSchema,\n\t...(def.constrainedSampling === undefined ? {} : { constrainedSampling: def.constrainedSampling }),\n});\n"],"mappings":";;;;;;;;;;;;;;;AA0BA,MAAa,kBAAkB,OAAO,OAAO;CAC5C,QAAQ,OAAO;CACf,UAAU,OAAO;CACjB,SAAS,OAAO,OAAO,OAAO,QAAQ,OAAO,OAAO;AACrD,CAAC;;AAiGD,MAAa,UAMZ,WAC8C,EAC9C,GAAG,MACJ;;AAGA,MAAa,aAOZ,YACA,aACkD;CAAE;CAAY;AAAQ;;AAGzE,MAAa,QAOZ,UAGiD;CACjD,MAAM,EAAE,SAAS,GAAG,SAAS;CAC7B,OAAO;EAAE,YAAY,OAAO,IAAI;EAAG;CAAQ;AAC5C;AAiBA,MAAM,gBAML,YACA,aACqB;CACrB;CAGA,UAAU,QAAQ,QACjB,QAAQ,QAA0B,GAAG,CAAC,CAAC,KACtC,OAAO,UAAU,UAAU,IAAI,mBAAmB;EAAE,UAAU,WAAW;EAAM;CAAM,CAAC,CAAC,CACxF;AACF;;AAGA,MAAa,YAMZ,SACoB,aAAa,KAAK,YAAY,KAAK,OAAO;;;;;;;AAQ/D,MAAa,WAOZ,MACA,UAKA,aAAa,KAAK,cAAc,QAAQ,QAAQ,KAAK,QAAQ,QAAQ,GAAG,CAAC,CAAC,KAAK,OAAO,QAAQ,KAAK,CAAC,EAKnG;;;;;;AAOF,MAAa,wBAAwB,WAAgD;CAGpF,MAAM,UAAU,UAAU,UAAU,OAAO,GAAG;CAC9C,IACC,UAAU,UAAU,OAAO,KAC3B,QAAQ,mBAAmB,WAAW,KACtC,QAAQ,gBAAgB,WAAW,GAEnC,OAAO;EAAE,MAAM;EAAU,YAAY,CAAC;EAAG,sBAAsB;CAAK;CAErE,OAAO,OAAO,uBAAuB,MAAM,CAAC,CAAC,YAAY,CAAC,WAAW,MAAM,EAAE,QAAQ,WAAW,CAAC;AAClG;;;;;;AAOA,MAAa,eAAe,SAAmC;CAC9D,MAAM,IAAI;CACV,aAAa,IAAI;CACjB,YAAY,qBAAqB,IAAI,UAAU;CAC/C,GAAI,IAAI,wBAAwB,KAAA,IAAY,CAAC,IAAI,EAAE,qBAAqB,IAAI,oBAAoB;AACjG"}
|
|
1
|
+
{"version":3,"file":"tool.mjs","names":[],"sources":["../../src/tool.ts"],"sourcesContent":["import type { Message } from \"@codeworksh/aikit\";\nimport { Effect, JsonSchema, type Layer, Schema, SchemaAST, SchemaRepresentation } from \"effect\";\nimport type { TSchema } from \"typebox\";\nimport { ToolExecutionError } from \"./tool/error.ts\";\nimport type { ToolProgress } from \"./tool/progress.ts\";\n\n/**\n * The tool definition + handler model.\n *\n * A tool definition is pure, serializable data: name, description, and Effect\n * Schema for parameters / success / failure. Execution is a separate `Handler`\n * — an `Effect` whose capability dependencies (e.g. `ToolShell`) live in its\n * requirements `R`, provided by a Layer at runtime. Separating the two is the\n * main testing win: assert on the definition as plain data, and run the handler\n * against a stub capability Layer.\n *\n * Effect Schema is the single source of truth. {@link toAikitTool} derives a\n * provider-safe JSON Schema object for the aikit wire view; the harness\n * decode/encodes arguments and results with Effect Schema natively (it does not\n * use aikit's Typebox validators).\n */\n\n/** What the model reads next turn (the `content` side of content/details). */\nexport type ModelContent = ReadonlyArray<Message.TextContent | Message.ImageContent>;\n\n/** Per-call metadata handed to a handler instead of positional args. */\nexport const ToolCallContext = Schema.Struct({\n\tcallID: Schema.String,\n\ttoolName: Schema.String,\n\trawArgs: Schema.Record(Schema.String, Schema.Unknown),\n\t/** Input modalities of the model the call answers, e.g. `[\"text\", \"image\"]`. */\n\tmodelInput: Schema.optional(Schema.Array(Schema.Literals([\"text\", \"image\"]))),\n});\nexport type ToolCallContext = typeof ToolCallContext.Type;\n\n/**\n * Where a tool is reachable. `direct` and `model` tools are declared to the model each turn;\n * `model` ones are never callable from other tools. `codemode` and `deferred` tools stay off the\n * wire until loaded, and `hidden` ones never reach the model.\n */\nexport const ToolExposure = Schema.Literals([\"direct\", \"model\", \"codemode\", \"deferred\", \"hidden\"]);\nexport type ToolExposure = typeof ToolExposure.Type;\n\n/** Whether a tool is declared to the model every turn. Omitted exposure means `direct`. */\nexport const declared = (def: { readonly exposure?: ToolExposure }): boolean =>\n\tdef.exposure === undefined || def.exposure === \"direct\" || def.exposure === \"model\";\n\n/**\n * A pure tool definition. Parametrised over the *schema* instances so the\n * decoded parameter/success/failure types can be recovered via `[\"Type\"]`.\n */\nexport interface ToolDef<\n\tName extends string = string,\n\tParams extends Schema.Top = Schema.Top,\n\tSuccess extends Schema.Top = Schema.Top,\n\tFailure extends Schema.Top = Schema.Top,\n> {\n\treadonly name: Name;\n\treadonly description: string;\n\t/** Human-readable display label (kept from the previous `AgentTool`). */\n\treadonly label?: string;\n\t/**\n\t * A short one-line summary for compact tool listings (e.g. a system-prompt tool index),\n\t * distinct from the fuller `description`.\n\t */\n\treadonly promptSnippet?: string;\n\t/** Optional guideline bullets appended to the default system prompt Guidelines section when this tool is active. */\n\treadonly promptGuidelines?: ReadonlyArray<string>;\n\t/** Where the tool is reachable. Omit → `direct`. */\n\treadonly exposure?: ToolExposure;\n\t/**\n\t * Repair argument shapes models commonly send before they are validated against\n\t * `parameters`. Return a copy; a throw makes the arguments invalid.\n\t */\n\treadonly prepareArguments?: (args: unknown) => unknown;\n\treadonly parameters: Params;\n\t/**\n\t * How the provider constrains the generated arguments. `{ type: \"json_schema\", strict: \"prefer\" }` sends\n\t * `parameters` in strict mode where the provider can express it and falls back to non-strict otherwise.\n\t */\n\treadonly constrainedSampling?: Message.Tool[\"constrainedSampling\"];\n\treadonly success: Success;\n\t/** Declared, model-visible failures (typed). Omit for tools that cannot fail expectedly. */\n\treadonly failure?: Failure;\n\t/** Render success for the model. Omit → executor falls back to JSON text. */\n\treadonly encodeContent?: (success: Success[\"Type\"]) => ModelContent;\n\t/** Render an expected failure for the model. Omit → executor falls back to JSON text. */\n\treadonly encodeFailureContent?: (failure: Failure[\"Type\"]) => ModelContent;\n\t/**\n\t * The `details` kept with a success, for UIs and programmatic consumers. Omit → the encoded\n\t * success. Set it when `encodeContent` already carries the payload, so it is not stored twice.\n\t */\n\treadonly encodeDetails?: (success: Success[\"Type\"]) => unknown;\n}\n\n/** A handler: validated params + context → typed success or typed failure. */\nexport type Handler<Params extends Schema.Top, Success extends Schema.Top, Failure extends Schema.Top, R = never> = (\n\tparams: Params[\"Type\"],\n\tctx: ToolCallContext,\n) => Effect.Effect<Success[\"Type\"], Failure[\"Type\"], R>;\n\n/** A definition paired with its handler (the unit the executor runs). */\nexport interface ToolImpl<\n\tName extends string = string,\n\tParams extends Schema.Top = Schema.Top,\n\tSuccess extends Schema.Top = Schema.Top,\n\tFailure extends Schema.Top = Schema.Top,\n\tR = never,\n> {\n\treadonly definition: ToolDef<Name, Params, Success, Failure>;\n\treadonly handler: Handler<Params, Success, Failure, R>;\n}\n\n// Heterogeneous-collection aliases. `any` for the schema generics keeps handlers\n// of differing parameter types assignable into one array (the precise generics\n// live on the authoring helpers below).\n// biome-ignore lint/suspicious/noExplicitAny: erased schema generics for storage\nexport type AnyToolDef = ToolDef<string, any, any, any>;\n// biome-ignore lint/suspicious/noExplicitAny: erased schema generics for storage\nexport type AnyToolImpl<R = never> = ToolImpl<string, any, any, any, R>;\n\ninterface DefineInput<\n\tName extends string,\n\tParams extends Schema.Top,\n\tSuccess extends Schema.Top,\n\tFailure extends Schema.Top,\n> {\n\treadonly name: Name;\n\treadonly description: string;\n\treadonly label?: string;\n\treadonly promptSnippet?: string;\n\treadonly promptGuidelines?: ReadonlyArray<string>;\n\treadonly exposure?: ToolExposure;\n\treadonly prepareArguments?: (args: unknown) => unknown;\n\treadonly parameters: Params;\n\treadonly constrainedSampling?: Message.Tool[\"constrainedSampling\"];\n\treadonly success: Success;\n\treadonly failure?: Failure;\n\treadonly encodeContent?: (success: Success[\"Type\"]) => ModelContent;\n\treadonly encodeFailureContent?: (failure: Failure[\"Type\"]) => ModelContent;\n\treadonly encodeDetails?: (success: Success[\"Type\"]) => unknown;\n}\n\n/** Define a pure tool (handler attached later via {@link implement} or a toolkit). */\nexport const define = <\n\tName extends string,\n\tParams extends Schema.Top,\n\tSuccess extends Schema.Top,\n\tFailure extends Schema.Top = Schema.Top,\n>(\n\tinput: DefineInput<Name, Params, Success, Failure>,\n): ToolDef<Name, Params, Success, Failure> => ({\n\t...input,\n});\n\n/** Attach a handler to an existing definition (the testable def/exec split). */\nexport const implement = <\n\tName extends string,\n\tParams extends Schema.Top,\n\tSuccess extends Schema.Top,\n\tFailure extends Schema.Top,\n\tR = never,\n>(\n\tdefinition: ToolDef<Name, Params, Success, Failure>,\n\thandler: Handler<Params, Success, Failure, R>,\n): ToolImpl<Name, Params, Success, Failure, R> => ({ definition, handler });\n\n/** Sugar for the co-located case: a definition with its handler in one object. */\nexport const make = <\n\tName extends string,\n\tParams extends Schema.Top,\n\tSuccess extends Schema.Top,\n\tFailure extends Schema.Top = Schema.Top,\n\tR = never,\n>(\n\tinput: DefineInput<Name, Params, Success, Failure> & {\n\t\treadonly handler: Handler<Params, Success, Failure, R>;\n\t},\n): ToolImpl<Name, Params, Success, Failure, R> => {\n\tconst { handler, ...rest } = input;\n\treturn { definition: define(rest), handler };\n};\n\n/**\n * A tool ready to register: its capability requirements have been discharged, leaving only\n * the executor-provided {@link ToolProgress}. The registry and executor hold `RegisteredTool`s\n * and are non-generic (only `handle` is generic, over a progress sink's `RProgress`), so any\n * number of tools — built-in or\n * third-party/plugin — compose without a shared capability union\n */\nexport interface RegisteredTool {\n\treadonly definition: AnyToolDef;\n\treadonly handler: (\n\t\tparams: unknown,\n\t\tctx: ToolCallContext,\n\t) => Effect.Effect<unknown, ToolExecutionError, ToolProgress>;\n}\n\nconst toRegistered = <\n\tName extends string,\n\tParams extends Schema.Top,\n\tSuccess extends Schema.Top,\n\tFailure extends Schema.Top,\n>(\n\tdefinition: ToolDef<Name, Params, Success, Failure>,\n\thandler: Handler<Params, Success, Failure, ToolProgress>,\n): RegisteredTool => ({\n\tdefinition,\n\t// The executor decodes with `definition.parameters` before invoking this\n\t// erased handler, so restoring the authored parameter type is safe here.\n\thandler: (params, ctx) =>\n\t\thandler(params as Params[\"Type\"], ctx).pipe(\n\t\t\tEffect.mapError((cause) => new ToolExecutionError({ toolName: definition.name, cause })),\n\t\t),\n});\n\n/** Register a tool whose only requirement is the executor-provided progress service. */\nexport const register = <\n\tName extends string,\n\tParams extends Schema.Top,\n\tSuccess extends Schema.Top,\n\tFailure extends Schema.Top,\n>(\n\timpl: ToolImpl<Name, Params, Success, Failure, ToolProgress>,\n): RegisteredTool => toRegistered(impl.definition, impl.handler);\n\n/**\n * Discharge a tool's capability requirements into a {@link RegisteredTool}, erasing its `R`\n * (the executor still provides `ToolProgress`). This is the registration boundary: a\n * plugin/third-party tool provides its own fully-resolved capability Layer here, so the\n * registry never has to unify anyone's `R`.\n */\nexport const provide = <\n\tName extends string,\n\tParams extends Schema.Top,\n\tSuccess extends Schema.Top,\n\tFailure extends Schema.Top,\n\tR,\n>(\n\timpl: ToolImpl<Name, Params, Success, Failure, R | ToolProgress>,\n\tlayer: Layer.Layer<R>,\n): RegisteredTool =>\n\t// `Effect.provide` discharges `R`, leaving `ToolProgress`. TS can't simplify\n\t// `Exclude<ToolProgress, R>` for a generic `R`, so localize the cast before\n\t// crossing the registered-tool boundary.\n\ttoRegistered(impl.definition, ((params, ctx) => impl.handler(params, ctx).pipe(Effect.provide(layer))) as Handler<\n\t\tParams,\n\t\tSuccess,\n\t\tFailure,\n\t\tToolProgress\n\t>);\n\nconst providerJsonSchema = \"codework/providerJsonSchema\";\n\n/**\n * Parameters from a JSON Schema someone else wrote, such as an MCP server's `inputSchema`. The\n * provider receives it exactly as written; arguments are validated against its Effect translation,\n * `pattern`s included: the user chose the server. A schema the translation cannot express (an\n * external `$ref`, a pattern invalid in Unicode mode) validates nothing, since rejecting arguments\n * the schema allows would be worse than letting the server check them.\n */\nexport const fromJsonSchema = (schema: Record<string, unknown>): Schema.Top => {\n\tconst validator = (() => {\n\t\ttry {\n\t\t\tconst draft07 =\n\t\t\t\t(typeof schema.$schema === \"string\" && schema.$schema.includes(\"draft-07\")) || \"definitions\" in schema;\n\t\t\treturn SchemaRepresentation.fromJsonSchemaDocument(\n\t\t\t\tdraft07 ? JsonSchema.fromSchemaDraft07(schema) : JsonSchema.fromSchemaDraft2020_12(schema),\n\t\t\t\t{ patterns: \"apply\" },\n\t\t\t);\n\t\t} catch {\n\t\t\treturn Schema.Unknown;\n\t\t}\n\t})();\n\treturn validator.annotate({ [providerJsonSchema]: schema });\n};\n\n/**\n * Whether `schema` came from {@link fromJsonSchema}. Its arguments are checked as JSON Schema checks\n * them: a key a closed object does not declare is an error, not dropped, since the tool receives the\n * arguments as written.\n */\nexport const isFromJsonSchema = (schema: Schema.Top) =>\n\tSchemaAST.resolveAt<Record<string, unknown>>(providerJsonSchema)(schema.ast) !== undefined;\n\n/**\n * Derive a provider-safe JSON Schema object from an Effect Schema. This is the\n * single boundary that crosses into the provider wire; if a provider rejects a\n * construct, fix it here. Draft-07 inlines the root (no top-level `$ref`).\n */\nexport const toProviderJsonSchema = (schema: Schema.Top): Record<string, unknown> => {\n\tconst written = SchemaAST.resolveAt<Record<string, unknown>>(providerJsonSchema)(schema.ast);\n\tif (written !== undefined) return written;\n\t// Effect reads `Struct({})` as TS `{}` (any non-null) and emits `{ not: { type: \"null\" } }`;\n\t// providers require an object, so emit one shaped like a non-empty struct's.\n\tconst encoded = SchemaAST.toEncoded(schema.ast);\n\tif (\n\t\tSchemaAST.isObjects(encoded) &&\n\t\tencoded.propertySignatures.length === 0 &&\n\t\tencoded.indexSignatures.length === 0\n\t) {\n\t\treturn { type: \"object\", properties: {}, additionalProperties: true };\n\t}\n\treturn Schema.toStandardJSONSchemaV1(schema)[\"~standard\"].jsonSchema.input({ target: \"draft-07\" });\n};\n\n/**\n * Build the aikit `Message.Tool` wire view from a definition. The derived JSON\n * Schema object satisfies aikit's `parameters` slot structurally at runtime; the\n * single localized cast keeps aikit untouched (decision 3-A).\n */\nexport const toAikitTool = (def: AnyToolDef): Message.Tool => ({\n\tname: def.name,\n\tdescription: def.description,\n\tparameters: toProviderJsonSchema(def.parameters) as unknown as TSchema,\n\t...(def.constrainedSampling === undefined ? {} : { constrainedSampling: def.constrainedSampling }),\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;AA0BA,MAAa,kBAAkB,OAAO,OAAO;CAC5C,QAAQ,OAAO;CACf,UAAU,OAAO;CACjB,SAAS,OAAO,OAAO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C,CAAC,SAAS,GAAG,qBAAqB,OAAO,CAAC;AAC3D;;;;;;AAOA,MAAa,oBAAoB,WAChC,UAAU,UAAmC,kBAAkB,CAAC,CAAC,OAAO,GAAG,MAAM,KAAA;;;;;;AAOlF,MAAa,wBAAwB,WAAgD;CACpF,MAAM,UAAU,UAAU,UAAmC,kBAAkB,CAAC,CAAC,OAAO,GAAG;CAC3F,IAAI,YAAY,KAAA,GAAW,OAAO;CAGlC,MAAM,UAAU,UAAU,UAAU,OAAO,GAAG;CAC9C,IACC,UAAU,UAAU,OAAO,KAC3B,QAAQ,mBAAmB,WAAW,KACtC,QAAQ,gBAAgB,WAAW,GAEnC,OAAO;EAAE,MAAM;EAAU,YAAY,CAAC;EAAG,sBAAsB;CAAK;CAErE,OAAO,OAAO,uBAAuB,MAAM,CAAC,CAAC,YAAY,CAAC,WAAW,MAAM,EAAE,QAAQ,WAAW,CAAC;AAClG;;;;;;AAOA,MAAa,eAAe,SAAmC;CAC9D,MAAM,IAAI;CACV,aAAa,IAAI;CACjB,YAAY,qBAAqB,IAAI,UAAU;CAC/C,GAAI,IAAI,wBAAwB,KAAA,IAAY,CAAC,IAAI,EAAE,qBAAqB,IAAI,oBAAoB;AACjG"}
|
package/plugin-XaYYRsX-.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"plugin-XaYYRsX-.mjs","names":[],"sources":["../../src/plugin/plugin.ts","../../src/plugin.ts"],"sourcesContent":["import type { Effect } from \"effect\";\nimport type { Definition } from \"../event.ts\";\nimport type { Service as LocationService } from \"../location.ts\";\nimport type { SandboxIO } from \"../sandbox/io.ts\";\nimport type { SharedPluginContext } from \"./context.ts\";\nimport type { PluginOptions } from \"./ref.ts\";\n\n/**\n * The domains a plugin can extend, and the order the harness runs them in.\n *\n * Order is declared, not positional. A plugin's place used to come from where its entry sat in\n * the `plugins` array, which is unknowable when the entry is written: a user's settings file and\n * a project's are edited by different people at different times, and neither can see the other's\n * order. Since a prompt plugin indexes the tools registered before it, that made a tool added\n * from settings invisible in the system prompt, with no way to fix it from a settings file.\n *\n * A plugin instead says which domain it extends, and the harness runs the domains in this order.\n * Entries within one domain keep the order they were written in, because that is where\n * composition actually happens -- a plugin patching another's tool, or appending to the prompt a\n * previous one rendered, is written next to it and deliberately after it.\n *\n * Kept as data so a later release can add a domain, or make the order configurable, without\n * touching the loader: `{ tool: 1, skill: 2, prompt: 3 }` needs no code change here.\n */\nexport const domains = { tool: 1, prompt: 2 } as const;\n\nexport type PluginKind = keyof typeof domains;\n\n/** Sort key for a plugin: its domain first, then where it was written. */\nexport const rank = (kind: PluginKind) => domains[kind];\n\nexport type Mount = SandboxIO.Provides | LocationService;\nexport interface Plugin {\n\treadonly id: string;\n\t/**\n\t * The domain this plugin extends, which decides when it runs: every `tool` plugin is set up\n\t * before any `prompt` plugin, whichever settings layer each came from, so a prompt plugin\n\t * always sees the complete tool set. Plugins within one domain run in the order they were\n\t * written.\n\t */\n\treadonly kind: PluginKind;\n\t/**\n\t * Event definitions this plugin publishes. Declared rather than registered at\n\t * runtime so they are known before the event system builds, and so a bad type\n\t * fails the boot instead of the first publish. Types must be namespaced\n\t * `plugin.<id>.*`.\n\t */\n\treadonly events?: ReadonlyArray<Definition>;\n\t/**\n\t * Off until a user asks for it. An `optIn` plugin is selected like any other but runs only\n\t * when a settings entry turns it on: `{ \"plugin\": \"<id>\", \"enabled\": true }`.\n\t */\n\treadonly optIn?: boolean;\n\t/**\n\t * `options` is this plugin's own configuration block, `{}` when its entry carried none.\n\t * Unvalidated: the harness never looks inside it, so a plugin checks whatever shape it\n\t * documents. It is a second argument rather than a context field so `ctx` stays one object\n\t * shared by every plugin in the exchange.\n\t */\n\treadonly setup: (\n\t\tctx: SharedPluginContext,\n\t\toptions: PluginOptions,\n\t) => void | Promise<void> | Effect.Effect<void, unknown, Mount>;\n}\n\nexport const define = (plugin: Plugin): Plugin => plugin;\n","/**\n * The plugin authoring surface.\n *\n * Everything a third-party plugin needs to describe itself and to write into the harness during\n * `setup`, and nothing about how the harness finds, installs or runs it. Loading, the store and\n * the `.npmrc` anchoring stay in `@codeworksh/harness`, which imports this same module — so a\n * plugin and its host agree on one set of types rather than two that happen to match.\n */\nexport type { Config, Events, Paths, PromptResolver, SharedPluginContext } from \"./plugin/context.ts\";\nexport { define, domains, type Mount, type Plugin, type PluginKind, rank } from \"./plugin/plugin.ts\";\nexport * as Prompt from \"./plugin/prompt.ts\";\nexport * as Section from \"./plugin/section.ts\";\nexport type { PluginOptions, PluginPatch, PluginRef, PluginSpec } from \"./plugin/ref.ts\";\nexport type { PluginRegistry } from \"./plugin/registry.ts\";\nexport * as Tool from \"./plugin/tool.ts\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAwBA,MAAa,UAAU;CAAE,MAAM;CAAG,QAAQ;AAAE;;AAK5C,MAAa,QAAQ,SAAqB,QAAQ;AAoClD,MAAa,UAAU,WAA2B"}
|