@anvia/core 1.0.8 → 1.1.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.
Files changed (62) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +16 -3
  3. package/dist/agent/index.d.ts +12 -12
  4. package/dist/agent/index.js +5 -5
  5. package/dist/agent/interactions/index.d.ts +1 -1
  6. package/dist/{agent-B-3jCRmI.d.ts → agent-DTmzs1Qr.d.ts} +16 -13
  7. package/dist/chunk-4UQALF5Y.js +117 -0
  8. package/dist/chunk-4UQALF5Y.js.map +1 -0
  9. package/dist/{chunk-XMVOBX43.js → chunk-JLJMVRRE.js} +2 -2
  10. package/dist/{chunk-DHJL44R2.js → chunk-JTJU56ZV.js} +2 -2
  11. package/dist/{chunk-TB5EKZM7.js → chunk-OI3LSMJG.js} +30 -1
  12. package/dist/chunk-OI3LSMJG.js.map +1 -0
  13. package/dist/{chunk-34EDX4ZL.js → chunk-Q5BCNYED.js} +2 -2
  14. package/dist/{chunk-HNRNTFMQ.js → chunk-XU54PLSD.js} +17 -6
  15. package/dist/chunk-XU54PLSD.js.map +1 -0
  16. package/dist/completion/index.d.ts +3 -3
  17. package/dist/completion/index.js +10 -2
  18. package/dist/{dynamic-tools-aIZlg5x1.d.ts → dynamic-tools-CNHSPXr1.d.ts} +3 -3
  19. package/dist/evals/index.d.ts +6 -6
  20. package/dist/evals/index.js +3 -3
  21. package/dist/extractor/index.d.ts +1 -1
  22. package/dist/extractor/index.js +3 -3
  23. package/dist/guardrails/index.d.ts +4 -4
  24. package/dist/image-generation/index.d.ts +1 -1
  25. package/dist/index.d.ts +14 -14
  26. package/dist/index.js +10 -5
  27. package/dist/internal/agent.d.ts +11 -11
  28. package/dist/internal/agent.js +6 -5
  29. package/dist/internal/agent.js.map +1 -1
  30. package/dist/mcp/index.d.ts +4 -4
  31. package/dist/memory/index.d.ts +3 -3
  32. package/dist/memory/index.js +2 -2
  33. package/dist/{middleware-kcF8AusP.d.ts → middleware-mY_lpjDp.d.ts} +1 -1
  34. package/dist/observability/index.d.ts +6 -6
  35. package/dist/observability/index.js +3 -3
  36. package/dist/pipeline/index.d.ts +12 -12
  37. package/dist/pipeline/index.js +3 -3
  38. package/dist/pipeline/index.js.map +1 -1
  39. package/dist/{provider-output-error-BEwDgVv3.d.ts → provider-output-error-OQ4fjw5W.d.ts} +10 -2
  40. package/dist/skills/index.d.ts +4 -4
  41. package/dist/speech-generation/index.d.ts +1 -1
  42. package/dist/{text-ZLECpQE7.d.ts → text-CmjXxakS.d.ts} +1 -1
  43. package/dist/{think-tool-BwCsJ365.d.ts → think-tool-YWsV98I5.d.ts} +1 -1
  44. package/dist/tool/index.d.ts +6 -6
  45. package/dist/{tool-BpqpoRSE.d.ts → tool-DQMZpZSS.d.ts} +1 -1
  46. package/dist/transcription/index.d.ts +1 -1
  47. package/dist/{types-DC1U1XwW.d.ts → types-C1xYKXF2.d.ts} +1 -1
  48. package/dist/{types-CXNE592e.d.ts → types-CODGMHnp.d.ts} +1 -1
  49. package/dist/{types-DL7wX6hJ.d.ts → types-CRda8x7p.d.ts} +8 -7
  50. package/dist/{types-DmzRCbU5.d.ts → types-CafU6Ux5.d.ts} +1 -1
  51. package/dist/{types-DgvozfPc.d.ts → types-CiHjqE6J.d.ts} +19 -3
  52. package/dist/{types-DjqRHeAi.d.ts → types-DfRPfehE.d.ts} +2 -2
  53. package/dist/{types-DhkodEft.d.ts → types-h0EL6Xn0.d.ts} +1 -1
  54. package/dist/vector-store/index.d.ts +4 -4
  55. package/package.json +1 -2
  56. package/dist/chunk-D4PACGPA.js +0 -37
  57. package/dist/chunk-D4PACGPA.js.map +0 -1
  58. package/dist/chunk-HNRNTFMQ.js.map +0 -1
  59. package/dist/chunk-TB5EKZM7.js.map +0 -1
  60. /package/dist/{chunk-XMVOBX43.js.map → chunk-JLJMVRRE.js.map} +0 -0
  61. /package/dist/{chunk-DHJL44R2.js.map → chunk-JTJU56ZV.js.map} +0 -0
  62. /package/dist/{chunk-34EDX4ZL.js.map → chunk-Q5BCNYED.js.map} +0 -0
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2026 Indra Zulfi
3
+ Copyright (c) 2026 Anvia
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -202,14 +202,27 @@ const result = await generateCompletion({
202
202
  prompt: "Summarize this incident.",
203
203
  retries: { maxAttempts: 3, initialDelayMs: 100, maxDelayMs: 1_000 },
204
204
  abortSignal: controller.signal,
205
- providerOptions: { reasoning: { effort: "medium" } },
205
+ controls: { reasoningEffort: "medium" },
206
206
  });
207
207
  ```
208
208
 
209
- `providerOptions` contains a strict JSON object passed to an adapter. Runtime values such as
209
+ Completion models can advertise typed, provider-neutral `controls`. Reasoning-capable adapters use
210
+ the `reasoningEffort` select control, so supported values are inferred from the model returned by
211
+ `completionModel()`. An Agent can set control defaults, and a generate or stream call can override
212
+ them for that run:
213
+
214
+ ```ts
215
+ const agent = new Agent({ model, controls: { reasoningEffort: "medium" } });
216
+ await agent.generate({ prompt: "Solve this.", controls: { reasoningEffort: "high" } });
217
+ ```
218
+
219
+ Omitting a control means “Default”: the Agent default applies when configured, otherwise the
220
+ provider chooses. Invalid control names and values are rejected before the provider call.
221
+
222
+ `providerOptions` remains the escape hatch for a strict JSON object passed to an adapter. Runtime values such as
210
223
  `undefined`, non-finite numbers, cycles, a top-level array, and class instances are rejected rather
211
224
  than coerced. Nested arrays are valid JSON. Canonical Anvia fields such as model, input,
212
- temperature, tools, dimensions, text, and voice take precedence over conflicting provider keys.
225
+ temperature, tools, controls, dimensions, text, and voice take precedence over conflicting provider keys.
213
226
  Cancellation is forwarded to provider SDK calls and is never retried.
214
227
 
215
228
  ## Agents
@@ -1,22 +1,22 @@
1
1
  export { M as ModelCallOptions } from '../model-call-options-CZkSw_xN.js';
2
2
  export { R as RetryContext, a as RetryOptions, b as RetrySetting } from '../retry-CjvSlKGW.js';
3
- export { A as Agent, a as AgentContextInput, b as AgentMemory, c as AgentMemoryOptions, d as AgentOptions, e as AgentToolInput, f as AgentToolOptions, C as CreateHybridVectorContextOptions, g as CreateVectorContextOptions, V as VectorContext, h as VectorContextBaseOptions, i as createVectorContext, j as isVectorContext } from '../agent-B-3jCRmI.js';
4
- import { M as Message, U as Usage, C as CompletionFinishReason } from '../types-DgvozfPc.js';
5
- import { A as AgentBlockedOutcome, g as AgentInteractionOutcome } from '../types-DL7wX6hJ.js';
6
- export { a as AgentChildStreamEvent, b as AgentDeltaEvent, c as AgentErrorEvent, d as AgentErrorStreamEvent, e as AgentFinishEvent, f as AgentInput, h as AgentLifecycle, i as AgentMemoryCompactionEvent, j as AgentMemoryCompactionOptions, k as AgentOutcome, l as AgentPrompt, m as AgentResponse, n as AgentRunOptions, o as AgentRunSettings, p as AgentStartEvent, q as AgentSteerInput, r as AgentSteerReceipt, s as AgentStepFinishEvent, t as AgentStream, u as AgentStreamEvent, v as AgentToolCallDeltaEvent, w as AgentToolFinishEvent, x as AgentToolStartEvent } from '../types-DL7wX6hJ.js';
3
+ export { A as Agent, a as AgentContextInput, b as AgentMemory, c as AgentMemoryOptions, d as AgentOptions, e as AgentToolInput, f as AgentToolOptions, C as CreateHybridVectorContextOptions, g as CreateVectorContextOptions, V as VectorContext, h as VectorContextBaseOptions, i as createVectorContext, j as isVectorContext } from '../agent-DTmzs1Qr.js';
4
+ import { M as Message, U as Usage, c as CompletionFinishReason } from '../types-CiHjqE6J.js';
5
+ import { A as AgentBlockedOutcome, g as AgentInteractionOutcome } from '../types-CRda8x7p.js';
6
+ export { a as AgentChildStreamEvent, b as AgentDeltaEvent, c as AgentErrorEvent, d as AgentErrorStreamEvent, e as AgentFinishEvent, f as AgentInput, h as AgentLifecycle, i as AgentMemoryCompactionEvent, j as AgentMemoryCompactionOptions, k as AgentOutcome, l as AgentPrompt, m as AgentResponse, n as AgentRunOptions, o as AgentRunSettings, p as AgentStartEvent, q as AgentSteerInput, r as AgentSteerReceipt, s as AgentStepFinishEvent, t as AgentStream, u as AgentStreamEvent, v as AgentToolCallDeltaEvent, w as AgentToolFinishEvent, x as AgentToolStartEvent } from '../types-CRda8x7p.js';
7
7
  import '../zod-schema-C7F4clpm.js';
8
8
  import 'zod';
9
- import '../types-DhkodEft.js';
9
+ import '../types-h0EL6Xn0.js';
10
10
  import '../type-utils-CtHVDRn_.js';
11
- import '../types-DjqRHeAi.js';
12
- import '../tool-BpqpoRSE.js';
13
- import '../types-DmzRCbU5.js';
14
- import '../middleware-kcF8AusP.js';
11
+ import '../types-DfRPfehE.js';
12
+ import '../tool-DQMZpZSS.js';
13
+ import '../types-CafU6Ux5.js';
14
+ import '../middleware-mY_lpjDp.js';
15
15
  import './interactions/index.js';
16
- import '../types-DC1U1XwW.js';
17
- import '../dynamic-tools-aIZlg5x1.js';
16
+ import '../types-C1xYKXF2.js';
17
+ import '../dynamic-tools-CNHSPXr1.js';
18
18
  import '../types-Cr4uiYo5.js';
19
- import '../types-CXNE592e.js';
19
+ import '../types-CODGMHnp.js';
20
20
 
21
21
  type AgentStructuredOutputPhase = "truncated" | "content-filter" | "parse" | "schema";
22
22
  type AgentStructuredOutputFormat = "raw" | "json-fence" | "unlabeled-fence";
@@ -2,11 +2,11 @@ import {
2
2
  Agent,
3
3
  createVectorContext,
4
4
  isVectorContext
5
- } from "../chunk-HNRNTFMQ.js";
5
+ } from "../chunk-XU54PLSD.js";
6
6
  import "../chunk-OJBFDBLG.js";
7
7
  import "../chunk-J6LVLV6P.js";
8
- import "../chunk-XMVOBX43.js";
9
- import "../chunk-34EDX4ZL.js";
8
+ import "../chunk-JLJMVRRE.js";
9
+ import "../chunk-Q5BCNYED.js";
10
10
  import "../chunk-KSKST3KP.js";
11
11
  import "../chunk-YK4WAAS4.js";
12
12
  import "../chunk-2QZJTG2E.js";
@@ -22,8 +22,8 @@ import {
22
22
  } from "../chunk-AHLKV6KP.js";
23
23
  import "../chunk-K5L7R7XM.js";
24
24
  import "../chunk-IZNOP6JG.js";
25
- import "../chunk-D4PACGPA.js";
26
- import "../chunk-TB5EKZM7.js";
25
+ import "../chunk-4UQALF5Y.js";
26
+ import "../chunk-OI3LSMJG.js";
27
27
  import "../chunk-7JLAIN6E.js";
28
28
  import "../chunk-QGX73TSQ.js";
29
29
  import "../chunk-3XQGVDU5.js";
@@ -1,5 +1,5 @@
1
1
  import { z } from 'zod';
2
- import { p as JsonValue, J as JsonObject, $ as ToolQuestionAnswer } from '../../types-DgvozfPc.js';
2
+ import { t as JsonValue, J as JsonObject, a4 as ToolQuestionAnswer } from '../../types-CiHjqE6J.js';
3
3
  import '../../model-call-options-CZkSw_xN.js';
4
4
 
5
5
  type AgentQuestionChoice = Readonly<{
@@ -1,17 +1,17 @@
1
1
  import { b as RetrySetting } from './retry-CjvSlKGW.js';
2
- import { D as Document, c as CompletionModel, P as ProviderTool, J as JsonObject, v as ToolChoice } from './types-DgvozfPc.js';
2
+ import { D as Document, d as CompletionModel, P as ProviderTool, J as JsonObject, C as CompletionControlValues, f as CompletionModelControlsOf, z as ToolChoice } from './types-CiHjqE6J.js';
3
3
  import { Z as ZodSchema } from './zod-schema-C7F4clpm.js';
4
- import { d as GuardrailPolicyInput, c as GuardrailPolicy } from './types-DhkodEft.js';
5
- import { a as McpServer } from './types-DjqRHeAi.js';
6
- import { E as MemoryStore, z as MemorySavePolicy, F as MemoryTokenCounter, n as MemoryCompactor, d as MemoryCompactionConflictRetryOptions, y as MemoryOptions, k as MemoryCompactionResult } from './types-DmzRCbU5.js';
7
- import { h as AgentLifecycle, F as AgentObservabilityOptions, n as AgentRunOptions, k as AgentOutcome, o as AgentRunSettings, t as AgentStream, j as AgentMemoryCompactionOptions } from './types-DL7wX6hJ.js';
8
- import { A as AgentMiddleware } from './middleware-kcF8AusP.js';
9
- import { A as AnyTool, T as Tool, c as ToolCallContext, N as NormalizedToolOutput } from './tool-BpqpoRSE.js';
4
+ import { d as GuardrailPolicyInput, c as GuardrailPolicy } from './types-h0EL6Xn0.js';
5
+ import { a as McpServer } from './types-DfRPfehE.js';
6
+ import { E as MemoryStore, z as MemorySavePolicy, F as MemoryTokenCounter, n as MemoryCompactor, d as MemoryCompactionConflictRetryOptions, y as MemoryOptions, k as MemoryCompactionResult } from './types-CafU6Ux5.js';
7
+ import { h as AgentLifecycle, F as AgentObservabilityOptions, n as AgentRunOptions, k as AgentOutcome, o as AgentRunSettings, t as AgentStream, j as AgentMemoryCompactionOptions } from './types-CRda8x7p.js';
8
+ import { A as AgentMiddleware } from './middleware-mY_lpjDp.js';
9
+ import { A as AnyTool, T as Tool, c as ToolCallContext, N as NormalizedToolOutput } from './tool-DQMZpZSS.js';
10
10
  import { AgentContinuation, AgentInteractionResponse } from './agent/interactions/index.js';
11
- import { a as SkillSet } from './types-DC1U1XwW.js';
12
- import { T as ToolIndex } from './dynamic-tools-aIZlg5x1.js';
11
+ import { a as SkillSet } from './types-C1xYKXF2.js';
12
+ import { T as ToolIndex } from './dynamic-tools-CNHSPXr1.js';
13
13
  import { E as EmbeddingModel, c as SparseEmbeddingModel } from './types-Cr4uiYo5.js';
14
- import { V as VectorFilter, a as VectorSearchResult, d as VectorStore, H as HybridVectorStore, e as VectorFusion } from './types-CXNE592e.js';
14
+ import { V as VectorFilter, a as VectorSearchResult, d as VectorStore, H as HybridVectorStore, e as VectorFusion } from './types-CODGMHnp.js';
15
15
 
16
16
  type VectorContextBaseOptions<T = unknown> = {
17
17
  topK: number;
@@ -57,6 +57,7 @@ type AgentOptions<Output = string, M extends CompletionModel = CompletionModel,
57
57
  temperature?: number | undefined;
58
58
  maxTokens?: number | undefined;
59
59
  providerOptions?: JsonObject | undefined;
60
+ controls?: CompletionControlValues<CompletionModelControlsOf<M>> | undefined;
60
61
  retries?: RetrySetting | undefined;
61
62
  toolChoice?: ToolChoice | undefined;
62
63
  maxTurns?: number | undefined;
@@ -95,6 +96,7 @@ type ResolvedAgentOptions<Output = string, M extends CompletionModel = Completio
95
96
  temperature?: number | undefined;
96
97
  maxTokens?: number | undefined;
97
98
  providerOptions?: JsonObject | undefined;
99
+ controls?: CompletionControlValues<CompletionModelControlsOf<M>> | undefined;
98
100
  retries?: RetrySetting | undefined;
99
101
  tools?: readonly AnyTool[] | undefined;
100
102
  mcpServers?: readonly McpServer[] | undefined;
@@ -128,6 +130,7 @@ declare class Agent<Output = string, M extends CompletionModel = CompletionModel
128
130
  readonly temperature: number | undefined;
129
131
  readonly maxTokens: number | undefined;
130
132
  readonly providerOptions: JsonObject | undefined;
133
+ readonly controls: CompletionControlValues<CompletionModelControlsOf<M>> | undefined;
131
134
  readonly retries: RetrySetting | undefined;
132
135
  readonly mcpServers: readonly McpServer[];
133
136
  readonly tools: readonly AnyTool[];
@@ -140,9 +143,9 @@ declare class Agent<Output = string, M extends CompletionModel = CompletionModel
140
143
  readonly middlewares: readonly AgentMiddleware[];
141
144
  readonly memory: AgentMemory | undefined;
142
145
  constructor(options: AgentOptions<Output, M, ContextDocument>);
143
- generate(options: AgentRunOptions<Output, RawResponseOf<M>>): Promise<AgentOutcome<Output>>;
144
- resume(continuation: AgentContinuation, response: AgentInteractionResponse, settings?: AgentRunSettings<Output, RawResponseOf<M>>): Promise<AgentOutcome<Output>>;
145
- stream(options: AgentRunOptions<Output, RawResponseOf<M>>): AgentStream<Output, RawResponseOf<M>>;
146
+ generate(options: AgentRunOptions<Output, RawResponseOf<M>, CompletionModelControlsOf<M>>): Promise<AgentOutcome<Output>>;
147
+ resume(continuation: AgentContinuation, response: AgentInteractionResponse, settings?: AgentRunSettings<Output, RawResponseOf<M>, CompletionModelControlsOf<M>>): Promise<AgentOutcome<Output>>;
148
+ stream(options: AgentRunOptions<Output, RawResponseOf<M>, CompletionModelControlsOf<M>>): AgentStream<Output, RawResponseOf<M>>;
146
149
  compactMemory(options: AgentMemoryCompactionOptions): Promise<MemoryCompactionResult>;
147
150
  asTool(options: AgentToolOptions): Tool<{
148
151
  prompt: string;
@@ -0,0 +1,117 @@
1
+ // src/completion/controls.ts
2
+ var REASONING_EFFORT_CONTROL_ID = "reasoningEffort";
3
+ function defineCompletionModelControls(controls) {
4
+ if (typeof controls !== "object" || controls === null || Array.isArray(controls)) {
5
+ throw new TypeError("Completion model controls must be an object.");
6
+ }
7
+ const snapshot = {};
8
+ for (const [id, control] of Object.entries(controls)) {
9
+ if (id.trim().length === 0) {
10
+ throw new TypeError("Completion control ids must not be empty.");
11
+ }
12
+ if (typeof control !== "object" || control === null || Array.isArray(control)) {
13
+ throw new TypeError(`Completion control "${id}" must be an object.`);
14
+ }
15
+ if (control.type !== "select") {
16
+ throw new TypeError(`Completion control "${id}" must have type "select".`);
17
+ }
18
+ if (typeof control.label !== "string" || control.label.trim().length === 0) {
19
+ throw new TypeError(`Completion control "${id}" must have a non-empty label.`);
20
+ }
21
+ if (!Array.isArray(control.options) || control.options.length === 0) {
22
+ throw new TypeError(`Completion control "${id}" must declare at least one option.`);
23
+ }
24
+ const options = control.options.map((option) => {
25
+ if (typeof option !== "string" || option.trim().length === 0) {
26
+ throw new TypeError(`Completion control "${id}" options must not be empty.`);
27
+ }
28
+ return option;
29
+ });
30
+ if (new Set(options).size !== options.length) {
31
+ throw new TypeError(`Completion control "${id}" options must be unique.`);
32
+ }
33
+ if (control.defaultValue !== void 0 && (typeof control.defaultValue !== "string" || !options.includes(control.defaultValue))) {
34
+ throw new TypeError(
35
+ `Completion control "${id}" defaultValue must be one of its declared options.`
36
+ );
37
+ }
38
+ if (control.description !== void 0 && typeof control.description !== "string") {
39
+ throw new TypeError(`Completion control "${id}" description must be a string.`);
40
+ }
41
+ let next = {
42
+ type: "select",
43
+ label: control.label,
44
+ options: Object.freeze(options)
45
+ };
46
+ if (control.description !== void 0) {
47
+ next = { ...next, description: control.description };
48
+ }
49
+ if (control.defaultValue !== void 0) {
50
+ next = { ...next, defaultValue: control.defaultValue };
51
+ }
52
+ Object.defineProperty(snapshot, id, {
53
+ value: Object.freeze(next),
54
+ enumerable: true,
55
+ configurable: false,
56
+ writable: false
57
+ });
58
+ }
59
+ return Object.freeze(snapshot);
60
+ }
61
+ function mergeCompletionControlValues(defaults, overrides) {
62
+ if (defaults === void 0 && overrides === void 0) return void 0;
63
+ const values = {};
64
+ for (const source of [defaults, overrides]) {
65
+ for (const [id, value] of Object.entries(source ?? {})) {
66
+ if (typeof value !== "string") continue;
67
+ Object.defineProperty(values, id, {
68
+ value,
69
+ enumerable: true,
70
+ configurable: true,
71
+ writable: true
72
+ });
73
+ }
74
+ }
75
+ return Object.keys(values).length === 0 ? void 0 : Object.freeze(values);
76
+ }
77
+
78
+ // src/completion/documents.ts
79
+ function normalizeDocuments(documents) {
80
+ if (documents.length === 0) {
81
+ return void 0;
82
+ }
83
+ return { role: "user", content: documents.map(formatDocument).join("\n") };
84
+ }
85
+ function formatDocument(document) {
86
+ return `<file id: ${document.id}>
87
+ ${formatDocumentBody(document)}
88
+ </file>
89
+ `;
90
+ }
91
+ function formatDocumentBody(document) {
92
+ const metadata = formatMetadata(document.additionalProps);
93
+ return metadata === void 0 ? document.text : `${metadata}
94
+ ${document.text}`;
95
+ }
96
+ function formatMetadata(additionalProps) {
97
+ if (additionalProps === void 0) {
98
+ return void 0;
99
+ }
100
+ const entries = Object.entries(additionalProps).sort(
101
+ ([left], [right]) => left.localeCompare(right)
102
+ );
103
+ if (entries.length === 0) {
104
+ return void 0;
105
+ }
106
+ const metadata = entries.map(([key, value]) => `${key}: ${JSON.stringify(value)}`).join(" ");
107
+ return `<metadata ${metadata} />`;
108
+ }
109
+
110
+ export {
111
+ REASONING_EFFORT_CONTROL_ID,
112
+ defineCompletionModelControls,
113
+ mergeCompletionControlValues,
114
+ normalizeDocuments,
115
+ formatDocument
116
+ };
117
+ //# sourceMappingURL=chunk-4UQALF5Y.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/completion/controls.ts","../src/completion/documents.ts"],"sourcesContent":["import type {\n CompletionControlValues,\n CompletionModelControls,\n CompletionModelSelectControl,\n} from \"./types\";\n\nexport const REASONING_EFFORT_CONTROL_ID = \"reasoningEffort\";\n\nexport type ReasoningEffortControls<Effort extends string = string> = Readonly<{\n reasoningEffort: CompletionModelSelectControl<Effort>;\n}>;\n\nexport function defineCompletionModelControls<const Controls extends CompletionModelControls>(\n controls: Controls,\n): Controls {\n if (typeof controls !== \"object\" || controls === null || Array.isArray(controls)) {\n throw new TypeError(\"Completion model controls must be an object.\");\n }\n const snapshot: Record<string, CompletionModelSelectControl> = {};\n for (const [id, control] of Object.entries(controls)) {\n if (id.trim().length === 0) {\n throw new TypeError(\"Completion control ids must not be empty.\");\n }\n if (typeof control !== \"object\" || control === null || Array.isArray(control)) {\n throw new TypeError(`Completion control \"${id}\" must be an object.`);\n }\n if (control.type !== \"select\") {\n throw new TypeError(`Completion control \"${id}\" must have type \"select\".`);\n }\n if (typeof control.label !== \"string\" || control.label.trim().length === 0) {\n throw new TypeError(`Completion control \"${id}\" must have a non-empty label.`);\n }\n if (!Array.isArray(control.options) || control.options.length === 0) {\n throw new TypeError(`Completion control \"${id}\" must declare at least one option.`);\n }\n const options = control.options.map((option) => {\n if (typeof option !== \"string\" || option.trim().length === 0) {\n throw new TypeError(`Completion control \"${id}\" options must not be empty.`);\n }\n return option;\n });\n if (new Set(options).size !== options.length) {\n throw new TypeError(`Completion control \"${id}\" options must be unique.`);\n }\n if (\n control.defaultValue !== undefined &&\n (typeof control.defaultValue !== \"string\" || !options.includes(control.defaultValue))\n ) {\n throw new TypeError(\n `Completion control \"${id}\" defaultValue must be one of its declared options.`,\n );\n }\n if (control.description !== undefined && typeof control.description !== \"string\") {\n throw new TypeError(`Completion control \"${id}\" description must be a string.`);\n }\n let next: CompletionModelSelectControl = {\n type: \"select\",\n label: control.label,\n options: Object.freeze(options),\n };\n if (control.description !== undefined) {\n next = { ...next, description: control.description };\n }\n if (control.defaultValue !== undefined) {\n next = { ...next, defaultValue: control.defaultValue };\n }\n Object.defineProperty(snapshot, id, {\n value: Object.freeze(next),\n enumerable: true,\n configurable: false,\n writable: false,\n });\n }\n return Object.freeze(snapshot) as Controls;\n}\n\nexport function mergeCompletionControlValues<Controls extends CompletionModelControls>(\n defaults: CompletionControlValues<Controls> | undefined,\n overrides: CompletionControlValues<Controls> | undefined,\n): Readonly<Record<string, string>> | undefined {\n if (defaults === undefined && overrides === undefined) return undefined;\n const values: Record<string, string> = {};\n for (const source of [defaults, overrides]) {\n for (const [id, value] of Object.entries(source ?? {})) {\n if (typeof value !== \"string\") continue;\n Object.defineProperty(values, id, {\n value,\n enumerable: true,\n configurable: true,\n writable: true,\n });\n }\n }\n return Object.keys(values).length === 0 ? undefined : Object.freeze(values);\n}\n","import type { Document, Message } from \"./types\";\n\nexport function normalizeDocuments(documents: Document[]): Message | undefined {\n if (documents.length === 0) {\n return undefined;\n }\n\n return { role: \"user\", content: documents.map(formatDocument).join(\"\\n\") };\n}\n\nexport function formatDocument(document: Document): string {\n return `<file id: ${document.id}>\\n${formatDocumentBody(document)}\\n</file>\\n`;\n}\n\nfunction formatDocumentBody(document: Document): string {\n const metadata = formatMetadata(document.additionalProps);\n return metadata === undefined ? document.text : `${metadata}\\n${document.text}`;\n}\n\nfunction formatMetadata(additionalProps: Record<string, string> | undefined): string | undefined {\n if (additionalProps === undefined) {\n return undefined;\n }\n\n const entries = Object.entries(additionalProps).sort(([left], [right]) =>\n left.localeCompare(right),\n );\n if (entries.length === 0) {\n return undefined;\n }\n\n const metadata = entries.map(([key, value]) => `${key}: ${JSON.stringify(value)}`).join(\" \");\n return `<metadata ${metadata} />`;\n}\n"],"mappings":";AAMO,IAAM,8BAA8B;AAMpC,SAAS,8BACd,UACU;AACV,MAAI,OAAO,aAAa,YAAY,aAAa,QAAQ,MAAM,QAAQ,QAAQ,GAAG;AAChF,UAAM,IAAI,UAAU,8CAA8C;AAAA,EACpE;AACA,QAAM,WAAyD,CAAC;AAChE,aAAW,CAAC,IAAI,OAAO,KAAK,OAAO,QAAQ,QAAQ,GAAG;AACpD,QAAI,GAAG,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,SAAS,OAAO,GAAG,QAAQ;AAAA,EAAK,SAAS,IAAI;AAC/E;AAEA,SAAS,eAAe,iBAAyE;AAC/F,MAAI,oBAAoB,QAAW;AACjC,WAAO;AAAA,EACT;AAEA,QAAM,UAAU,OAAO,QAAQ,eAAe,EAAE;AAAA,IAAK,CAAC,CAAC,IAAI,GAAG,CAAC,KAAK,MAClE,KAAK,cAAc,KAAK;AAAA,EAC1B;AACA,MAAI,QAAQ,WAAW,GAAG;AACxB,WAAO;AAAA,EACT;AAEA,QAAM,WAAW,QAAQ,IAAI,CAAC,CAAC,KAAK,KAAK,MAAM,GAAG,GAAG,KAAK,KAAK,UAAU,KAAK,CAAC,EAAE,EAAE,KAAK,GAAG;AAC3F,SAAO,aAAa,QAAQ;AAC9B;","names":[]}
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  generateCompletion
3
- } from "./chunk-TB5EKZM7.js";
3
+ } from "./chunk-OI3LSMJG.js";
4
4
 
5
5
  // src/memory/errors.ts
6
6
  var MemoryCompactionError = class extends Error {
@@ -282,4 +282,4 @@ export {
282
282
  resolveMemoryOptions,
283
283
  estimateMemoryTokens
284
284
  };
285
- //# sourceMappingURL=chunk-XMVOBX43.js.map
285
+ //# sourceMappingURL=chunk-JLJMVRRE.js.map
@@ -2,7 +2,7 @@ import {
2
2
  CompletionCapabilityError,
3
3
  Usage,
4
4
  generateCompletion
5
- } from "./chunk-TB5EKZM7.js";
5
+ } from "./chunk-OI3LSMJG.js";
6
6
  import {
7
7
  toProviderJsonSchema
8
8
  } from "./chunk-QGX73TSQ.js";
@@ -124,4 +124,4 @@ export {
124
124
  ExtractionError,
125
125
  extract
126
126
  };
127
- //# sourceMappingURL=chunk-DHJL44R2.js.map
127
+ //# sourceMappingURL=chunk-JTJU56ZV.js.map
@@ -240,6 +240,7 @@ var CompletionCapabilityError = class extends Error {
240
240
  function assertCompletionRequestSupported(model, request, options = {}) {
241
241
  const modelLabel = `${model.provider}:${model.modelId}`;
242
242
  const capabilities = model.capabilities;
243
+ assertCompletionControlsSupported(model, request.controls);
243
244
  if (options.streaming === true && !capabilities.streaming) {
244
245
  throw new CompletionCapabilityError(`${modelLabel} does not support streaming completions.`);
245
246
  }
@@ -262,6 +263,24 @@ function assertCompletionRequestSupported(model, request, options = {}) {
262
263
  throw new CompletionCapabilityError(`${modelLabel} does not support document file input.`);
263
264
  }
264
265
  }
266
+ function assertCompletionControlsSupported(model, controls) {
267
+ const modelLabel = `${model.provider}:${model.modelId}`;
268
+ for (const [controlId, value] of Object.entries(controls ?? {})) {
269
+ if (value === void 0) continue;
270
+ const modelControls = model.controls;
271
+ const control = modelControls !== void 0 && Object.hasOwn(modelControls, controlId) ? modelControls[controlId] : void 0;
272
+ if (control === void 0) {
273
+ throw new CompletionCapabilityError(
274
+ `${modelLabel} does not support completion control "${controlId}".`
275
+ );
276
+ }
277
+ if (!control.options.includes(value)) {
278
+ throw new CompletionCapabilityError(
279
+ `${modelLabel} completion control "${controlId}" does not support value "${value}".`
280
+ );
281
+ }
282
+ }
283
+ }
265
284
  function textFromAssistantContent(content) {
266
285
  return content.flatMap((item) => item.type === "text" ? [item.text] : []).join("\n");
267
286
  }
@@ -510,6 +529,14 @@ function createCompletionRequest(input, options) {
510
529
  if (options.maxTokens !== void 0) request.maxTokens = options.maxTokens;
511
530
  if (options.toolChoice !== void 0) request.toolChoice = options.toolChoice;
512
531
  if (options.outputSchema !== void 0) request.outputSchema = options.outputSchema;
532
+ if (options.controls !== void 0) {
533
+ const controls = Object.fromEntries(
534
+ Object.entries(options.controls).filter(
535
+ (entry) => typeof entry[1] === "string"
536
+ )
537
+ );
538
+ if (Object.keys(controls).length > 0) request.controls = Object.freeze(controls);
539
+ }
513
540
  if (options.providerOptions !== void 0) {
514
541
  assertJsonObject(options.providerOptions, "providerOptions");
515
542
  request.providerOptions = options.providerOptions;
@@ -1390,6 +1417,7 @@ function requestFromOptions(options) {
1390
1417
  temperature: options.temperature,
1391
1418
  maxTokens: options.maxTokens,
1392
1419
  toolChoice: options.toolChoice,
1420
+ controls: options.controls,
1393
1421
  providerOptions: options.providerOptions,
1394
1422
  outputSchema: "outputSchema" in options && options.outputSchema !== void 0 ? toProviderJsonSchema(options.outputSchema) : void 0
1395
1423
  });
@@ -1502,6 +1530,7 @@ export {
1502
1530
  getAssistantGenerationMetadata,
1503
1531
  CompletionCapabilityError,
1504
1532
  assertCompletionRequestSupported,
1533
+ assertCompletionControlsSupported,
1505
1534
  textFromAssistantContent,
1506
1535
  createCompletionRequest,
1507
1536
  COMPLETION_PROVIDER_OUTPUT_ERROR_CODE,
@@ -1513,4 +1542,4 @@ export {
1513
1542
  streamCompletion,
1514
1543
  isStreamingCompletionModel
1515
1544
  };
1516
- //# sourceMappingURL=chunk-TB5EKZM7.js.map
1545
+ //# sourceMappingURL=chunk-OI3LSMJG.js.map