import{expectBoolean,expectFunction,expectObjectRecord,expectOnlyKnownKeys,expectProviderOptions,expectString,getOptionalStringRecordProperty}from"#internal/authored-module.js";function normalizeAgentDefinition(e,t){let i=expectObjectRecord(e,t);if(expectOnlyKnownKeys(i,[`build`,`compaction`,`description`,`experimental`,`model`,`modelContextWindowTokens`,`modelOptions`,`outputSchema`],t),i.model===void 0)throw Error(`${t} The "model" field is required.`);let o={model:i.model};return i.description!==void 0&&(o.description=expectString(i.description,t)),i.compaction!==void 0&&(o.compaction=normalizeAgentCompactionDefinition(i.compaction,t)),i.build!==void 0&&(o.build=normalizeAgentBuildDefinition(i.build,t)),i.experimental!==void 0&&(o.experimental=normalizeAgentExperimentalDefinition(i.experimental,t)),i.modelOptions!==void 0&&(o.modelOptions=normalizeAgentModelOptions(i.modelOptions,t)),i.modelContextWindowTokens!==void 0&&(o.modelContextWindowTokens=expectPositiveInteger(i.modelContextWindowTokens,t)),i.outputSchema!==void 0&&(o.outputSchema=i.outputSchema),o}function expectPositiveInteger(e,t){if(typeof e!=`number`||!Number.isInteger(e)||e<=0)throw Error(t);return e}function normalizeAgentBuildDefinition(e,t){let i=expectObjectRecord(e,t);expectOnlyKnownKeys(i,[`externalDependencies`],t);let o={};if(i.externalDependencies!==void 0){if(!Array.isArray(i.externalDependencies))throw Error(t);o.externalDependencies=Object.freeze(i.externalDependencies.map(e=>expectString(e,t)))}return o}function normalizeAgentExperimentalDefinition(t,i){let a=expectObjectRecord(t,i);expectOnlyKnownKeys(a,[`codeMode`],i);let o={};return a.codeMode!==void 0&&(o.codeMode=expectBoolean(a.codeMode,i)),o}function normalizeAgentModelOptions(e,t){let a=expectObjectRecord(e,t);expectOnlyKnownKeys(a,[`providerOptions`],t);let o=a.providerOptions;return o===void 0?{}:{providerOptions:expectProviderOptions(o,t)}}function normalizeAgentCompactionDefinition(e,t){let i=expectObjectRecord(e,t);expectOnlyKnownKeys(i,[`model`,`modelContextWindowTokens`,`thresholdPercent`],t);let a={};if(i.model!==void 0&&(a.model=i.model),i.modelContextWindowTokens!==void 0&&(a.modelContextWindowTokens=expectPositiveInteger(i.modelContextWindowTokens,t)),i.thresholdPercent!==void 0){let e=i.thresholdPercent;if(typeof e!=`number`||!Number.isFinite(e)||e<0||e>1)throw Error(t);a.thresholdPercent=e}return a}function normalizeInstructionsDefinition(e,t){let i=expectObjectRecord(e,t);return expectOnlyKnownKeys(i,[`markdown`],t),{markdown:expectString(i.markdown,t)}}function normalizeSkillDefinition(e,t){let i=expectObjectRecord(e,t);expectOnlyKnownKeys(i,[`description`,`files`,`license`,`markdown`,`metadata`],t);let s={description:expectString(i.description,t),markdown:expectString(i.markdown,t)},c=i.license,l=getOptionalStringRecordProperty(i,`metadata`,t);return c!==void 0&&(s.license=expectString(c,t)),l!==void 0&&(s.metadata=l),i.files!==void 0&&(s.files=normalizeSkillFiles(i.files,t)),s}function normalizeSkillFiles(e,t){let r=expectObjectRecord(e,t),i={};for(let[e,n]of Object.entries(r)){if(typeof n==`string`||n instanceof Uint8Array){i[e]=n;continue}throw Error(`${t} Expected skill file "${e}" to be a string or Uint8Array.`)}return i}function normalizeScheduleDefinition(e,i){let o=expectObjectRecord(e,i);expectOnlyKnownKeys(o,[`cron`,`markdown`,`run`],i);let s=expectString(o.cron,i),c=o.markdown!==void 0,l=o.run!==void 0;if(c&&l)throw Error(`${i} Pass either "markdown" (fire-and-forget) or "run" (handler) — not both.`);if(!c&&!l)throw Error(`${i} Must provide either "markdown" (fire-and-forget) or "run" (handler).`);let u={cron:s};return c?u.markdown=expectString(o.markdown,i):u.run=expectFunction(o.run,i),u}export{normalizeAgentDefinition,normalizeInstructionsDefinition,normalizeScheduleDefinition,normalizeSkillDefinition};