@codeworksh/plugin 0.0.1-canary.10.1.g65d5c167 → 0.0.1-canary.12.1.gaa0eb2d3

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/index.d.mts CHANGED
@@ -1,3 +1,3 @@
1
1
  import { g as tool_d_exports } from "./tool-DuYBgiJf.mjs";
2
- import { t as plugin_d_exports } from "./plugin-DHCdfzdO.mjs";
2
+ import { t as plugin_d_exports } from "./plugin-C-N62_a5.mjs";
3
3
  export { plugin_d_exports as Plugin, tool_d_exports as Tool };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codeworksh/plugin",
3
- "version": "0.0.1-canary.10.1.g65d5c167",
3
+ "version": "0.0.1-canary.12.1.gaa0eb2d3",
4
4
  "description": "SDK for building CodeWork plugins — the plugin, tool, and sandbox contracts shared with @codeworksh/harness.",
5
5
  "keywords": [
6
6
  "agent",
@@ -163,7 +163,7 @@
163
163
  "uuidv7": "^1.2.1"
164
164
  },
165
165
  "peerDependencies": {
166
- "@codeworksh/aikit": "0.9.3-canary.10.1.g65d5c167",
166
+ "@codeworksh/aikit": "0.9.3-canary.12.1.gaa0eb2d3",
167
167
  "effect": "4.0.0-rc.115"
168
168
  }
169
169
  }
@@ -2,7 +2,7 @@ import { i as Definition, o as Payload, r as Data, s as PublishOptions } from ".
2
2
  import { n as SessionID } from "./ids-CHjmAdTc.mjs";
3
3
  import { r as Info, s as Service } from "./location-D4hAfuXF.mjs";
4
4
  import { a as Provides, r as Identity, u as io_d_exports } from "./io-BYs7hbiY.mjs";
5
- import { i as Info$1 } from "./settings-C6RxGd-M.mjs";
5
+ import { i as Info$1 } from "./settings-B6-grSTA.mjs";
6
6
  import { n as prompt_d_exports, t as PromptRegistry } from "./prompt-BcpagjGh.mjs";
7
7
  import { d as ToolRegistry, p as tool_d_exports } from "./tool-BoVqkYvL.mjs";
8
8
  import { Model } from "@codeworksh/aikit";
@@ -137,4 +137,4 @@ declare namespace plugin_d_exports {
137
137
  }
138
138
  //#endregion
139
139
  export { define as a, PluginOptions as c, PluginSpec as d, Config as f, PluginRegistry as g, SharedPluginContext as h, PluginKind as i, PluginPatch as l, PromptResolver as m, Mount as n, domains as o, Events as p, Plugin as r, rank as s, plugin_d_exports as t, PluginRef as u };
140
- //# sourceMappingURL=plugin-DHCdfzdO.d.mts.map
140
+ //# sourceMappingURL=plugin-C-N62_a5.d.mts.map
package/plugin.d.mts CHANGED
@@ -1,4 +1,4 @@
1
1
  import { n as prompt_d_exports } from "./prompt-BcpagjGh.mjs";
2
2
  import { p as tool_d_exports } from "./tool-BoVqkYvL.mjs";
3
- import { a as define, c as PluginOptions, d as PluginSpec, f as Config, g as PluginRegistry, h as SharedPluginContext, i as PluginKind, l as PluginPatch, m as PromptResolver, n as Mount, o as domains, p as Events, r as Plugin, s as rank, u as PluginRef } from "./plugin-DHCdfzdO.mjs";
3
+ import { a as define, c as PluginOptions, d as PluginSpec, f as Config, g as PluginRegistry, h as SharedPluginContext, i as PluginKind, l as PluginPatch, m as PromptResolver, n as Mount, o as domains, p as Events, r as Plugin, s as rank, u as PluginRef } from "./plugin-C-N62_a5.mjs";
4
4
  export { type Config, type Events, type Mount, type Plugin, type PluginKind, type PluginOptions, type PluginPatch, type PluginRef, type PluginRegistry, type PluginSpec, prompt_d_exports as Prompt, type PromptResolver, type SharedPluginContext, tool_d_exports as Tool, define, domains, rank };
@@ -272,6 +272,24 @@ declare const PluginEntry: Schema.Union<readonly [Schema.String, Schema.Union<re
272
272
  readonly package: Schema.String;
273
273
  }>]>]>;
274
274
  type PluginEntry = typeof PluginEntry.Type;
275
+ /**
276
+ * Agent-level retry of a turn whose provider request failed transiently (rate limit, overload,
277
+ * 5xx, dropped connection). Delays double from `baseDelayMs` and stop growing at `maxDelayMs`;
278
+ * a server that asks for a longer wait than `maxDelayMs` is not retried. `maxRetries: 0` is off.
279
+ *
280
+ * Separate from `model.options.maxRetries`, which retries inside the provider SDK and defaults to
281
+ * 0 so that the two do not multiply, and so a quota error reaches the loop instead of being retried.
282
+ */
283
+ declare const Retry: Schema.Struct<{
284
+ readonly maxRetries: Schema.optional<Schema.Int>;
285
+ readonly baseDelayMs: Schema.optional<Schema.Int>;
286
+ readonly maxDelayMs: Schema.optional<Schema.Int>;
287
+ }>;
288
+ interface RetryPolicy {
289
+ readonly maxRetries: number;
290
+ readonly baseDelayMs: number;
291
+ readonly maxDelayMs: number;
292
+ }
275
293
  declare const Patch: Schema.Struct<{
276
294
  readonly $schema: Schema.optional<Schema.String>;
277
295
  readonly plugins: Schema.optional<Schema.$Array<Schema.Union<readonly [Schema.String, Schema.Union<readonly [Schema.Struct<{
@@ -489,6 +507,11 @@ declare const Patch: Schema.Struct<{
489
507
  xhigh?: string | null;
490
508
  };
491
509
  }>, Schema.Unknown, never, never>>>;
510
+ readonly retry: Schema.optional<Schema.Struct<{
511
+ readonly maxRetries: Schema.optional<Schema.Int>;
512
+ readonly baseDelayMs: Schema.optional<Schema.Int>;
513
+ readonly maxDelayMs: Schema.optional<Schema.Int>;
514
+ }>>;
492
515
  }>;
493
516
  type Patch = typeof Patch.Type;
494
517
  /**
@@ -549,9 +572,10 @@ interface Info {
549
572
  readonly thinkingLevel: Model.ThinkingLevel;
550
573
  readonly toolExecution: ToolExecution;
551
574
  };
575
+ readonly retry: RetryPolicy;
552
576
  }
553
577
  /** Let aikit supply model-aware generation defaults. */
554
578
  declare const defaults: Info;
555
579
  //#endregion
556
- export { KeyReference as a, ModelProtocol as c, PluginPatch as d, ThinkingLevel as f, requestFields as g, keyName as h, Info as i, Patch as l, defaults as m, Declared as n, Model$1 as o, ToolExecution as p, DeclaredModel as r, ModelEntry as s, Block as t, PluginEntry as u };
557
- //# sourceMappingURL=settings-C6RxGd-M.d.mts.map
580
+ export { keyName as _, KeyReference as a, ModelProtocol as c, PluginPatch as d, Retry as f, defaults as g, ToolExecution as h, Info as i, Patch as l, ThinkingLevel as m, Declared as n, Model$1 as o, RetryPolicy as p, DeclaredModel as r, ModelEntry as s, Block as t, PluginEntry as u, requestFields as v };
581
+ //# sourceMappingURL=settings-B6-grSTA.d.mts.map
package/settings.d.mts CHANGED
@@ -1,2 +1,2 @@
1
- import { a as KeyReference, c as ModelProtocol, d as PluginPatch, f as ThinkingLevel, g as requestFields, h as keyName, i as Info, l as Patch, m as defaults, n as Declared, o as Model, p as ToolExecution, r as DeclaredModel, s as ModelEntry, t as Block, u as PluginEntry } from "./settings-C6RxGd-M.mjs";
2
- export { Block, Declared, DeclaredModel, Info, KeyReference, Model, ModelEntry, ModelProtocol, Patch, PluginEntry, PluginPatch, ThinkingLevel, ToolExecution, defaults, keyName, requestFields };
1
+ import { _ as keyName, a as KeyReference, c as ModelProtocol, d as PluginPatch, f as Retry, g as defaults, h as ToolExecution, i as Info, l as Patch, m as ThinkingLevel, n as Declared, o as Model, p as RetryPolicy, r as DeclaredModel, s as ModelEntry, t as Block, u as PluginEntry, v as requestFields } from "./settings-B6-grSTA.mjs";
2
+ export { Block, Declared, DeclaredModel, Info, KeyReference, Model, ModelEntry, ModelProtocol, Patch, PluginEntry, PluginPatch, Retry, RetryPolicy, ThinkingLevel, ToolExecution, defaults, keyName, requestFields };
package/settings.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { isAikitModelInfo, validateAikitModelInfo } from "./schema.mjs";
1
+ import { NonNegativeInt, isAikitModelInfo, validateAikitModelInfo } from "./schema.mjs";
2
2
  import { Model as Model$1 } from "@codeworksh/aikit";
3
3
  import { Effect, Schema, SchemaGetter, SchemaIssue } from "effect";
4
4
  //#region src/settings.ts
@@ -104,11 +104,25 @@ const PluginPatch = Schema.Union([Schema.Struct({
104
104
  ...config
105
105
  })], { mode: "oneOf" });
106
106
  const PluginEntry = Schema.Union([PluginReference, PluginPatch]);
107
+ /**
108
+ * Agent-level retry of a turn whose provider request failed transiently (rate limit, overload,
109
+ * 5xx, dropped connection). Delays double from `baseDelayMs` and stop growing at `maxDelayMs`;
110
+ * a server that asks for a longer wait than `maxDelayMs` is not retried. `maxRetries: 0` is off.
111
+ *
112
+ * Separate from `model.options.maxRetries`, which retries inside the provider SDK and defaults to
113
+ * 0 so that the two do not multiply, and so a quota error reaches the loop instead of being retried.
114
+ */
115
+ const Retry = Schema.Struct({
116
+ maxRetries: Schema.optional(NonNegativeInt),
117
+ baseDelayMs: Schema.optional(NonNegativeInt),
118
+ maxDelayMs: Schema.optional(NonNegativeInt)
119
+ });
107
120
  const Patch = Schema.Struct({
108
121
  $schema: Schema.optional(Schema.String),
109
122
  plugins: Schema.optional(Schema.Array(PluginEntry)),
110
123
  model: Schema.optional(Model),
111
- models: Schema.optional(Schema.Array(ModelEntry))
124
+ models: Schema.optional(Schema.Array(ModelEntry)),
125
+ retry: Schema.optional(Retry)
112
126
  });
113
127
  /** Let aikit supply model-aware generation defaults. */
114
128
  const defaults = {
@@ -122,11 +136,16 @@ const defaults = {
122
136
  toolExecution: "sequential",
123
137
  options: {
124
138
  timeoutMs: 36e5,
125
- maxRetries: 3
139
+ maxRetries: 0
126
140
  }
141
+ },
142
+ retry: {
143
+ maxRetries: 3,
144
+ baseDelayMs: 2e3,
145
+ maxDelayMs: 6e4
127
146
  }
128
147
  };
129
148
  //#endregion
130
- export { Block, KeyReference, Model, ModelEntry, ModelProtocol, Patch, PluginEntry, PluginPatch, ThinkingLevel, ToolExecution, defaults, keyName, requestFields };
149
+ export { Block, KeyReference, Model, ModelEntry, ModelProtocol, Patch, PluginEntry, PluginPatch, Retry, ThinkingLevel, ToolExecution, defaults, keyName, requestFields };
131
150
 
132
151
  //# sourceMappingURL=settings.mjs.map
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, 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\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\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});\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}\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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R;CACA,QAAQ,UAAU,IAAI,YAAY,aAAa,EAAE,SAAS,SAAS,KAAK,EAAE,GAAG,OAAO,OAAO;AAC5F,CAAC;;;;;AAMF,MAAa,aAAa,OAAO,QAAQ,KACxC,OAAO,SAAS,OAAO,QAAyB,kBAAkB,EAAE,UAAU,mBAAmB,CAAC,GAAG;CACpG,QAAQ,aAAa,gBAAgB,gBAAgB;CACrD,QAAQ,aAAa,gBAAgB,gBAAgB;AACtD,CAAC,CACF;;AAIA,MAAM,kBAAkB,OAAO,OAAO,MAAM,OAAO,WAAW,CAAC;;;;;;AAM/D,MAAM,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;AAGtE,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;AACjD,CAAC;;AAkED,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,YAAY;EAAE;CAChD;AACD"}
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\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: \"high\",\n\t\ttoolExecution: \"sequential\",\n\t\toptions: { timeoutMs: 3_600_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,gBAAgB;CAC5B,aAAa,OAAO,SAAS,OAAO,MAAM;CAC1C,WAAW,OAAO,SAAS,OAAO,MAAM;CACxC,gBAAgB,OAAO,SAAS,OAAO,SAAS;EAAC;EAAQ;EAAS;CAAM,CAAC,CAAC;CAC1E,SAAS,OAAO,SAAS,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