@agentsmarket/pipeline-runtime 0.5.0 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. package/README.md +86 -1
  2. package/dist/adapters/minimax.d.ts +16 -8
  3. package/dist/adapters/minimax.js +105 -26
  4. package/dist/adapters/multimodal-convert.d.ts +54 -0
  5. package/dist/adapters/multimodal-convert.js +105 -0
  6. package/dist/adapters/openrouter.d.ts +5 -0
  7. package/dist/adapters/openrouter.js +53 -6
  8. package/dist/index.d.ts +20 -4
  9. package/dist/index.js +15 -3
  10. package/dist/loop.d.ts +90 -0
  11. package/dist/loop.js +200 -0
  12. package/dist/memory.d.ts +73 -0
  13. package/dist/memory.js +119 -0
  14. package/dist/model-resolver.d.ts +52 -1
  15. package/dist/multimodal.d.ts +43 -0
  16. package/dist/multimodal.js +23 -0
  17. package/dist/output-errors.d.ts +93 -0
  18. package/dist/output-errors.js +128 -0
  19. package/dist/output-schema-validate.d.ts +10 -0
  20. package/dist/output-schema-validate.js +149 -0
  21. package/dist/output-schema.d.ts +66 -0
  22. package/dist/output-schema.js +141 -0
  23. package/dist/pipeline-refs.d.ts +15 -0
  24. package/dist/pipeline-refs.js +155 -0
  25. package/dist/provider-registry.d.ts +22 -1
  26. package/dist/provider-registry.js +62 -2
  27. package/dist/providers/anthropic.d.ts +28 -0
  28. package/dist/providers/anthropic.js +118 -0
  29. package/dist/providers/openai-chat.d.ts +28 -0
  30. package/dist/providers/openai-chat.js +106 -0
  31. package/dist/providers/openai-dalle.d.ts +19 -0
  32. package/dist/providers/openai-dalle.js +41 -0
  33. package/dist/providers/openai-tts.d.ts +19 -0
  34. package/dist/providers/openai-tts.js +46 -0
  35. package/dist/providers/openai-vision.d.ts +15 -0
  36. package/dist/providers/openai-vision.js +43 -0
  37. package/dist/providers/openai-whisper.d.ts +16 -0
  38. package/dist/providers/openai-whisper.js +43 -0
  39. package/dist/providers/replicate.d.ts +19 -0
  40. package/dist/providers/replicate.js +61 -0
  41. package/dist/providers/types.d.ts +23 -0
  42. package/dist/providers/types.js +31 -0
  43. package/dist/runtime-constraints.d.ts +2 -1
  44. package/dist/stages.d.ts +14 -2
  45. package/dist/stages.js +299 -29
  46. package/dist/streaming-events.d.ts +17 -2
  47. package/dist/streaming-events.js +12 -0
  48. package/dist/testing/assertions.d.ts +17 -0
  49. package/dist/testing/assertions.js +149 -0
  50. package/dist/testing/conformance.d.ts +3 -0
  51. package/dist/testing/conformance.js +28 -0
  52. package/dist/testing/coverage.d.ts +11 -0
  53. package/dist/testing/coverage.js +35 -0
  54. package/dist/testing/index.d.ts +9 -0
  55. package/dist/testing/index.js +9 -0
  56. package/dist/testing/reporters/json.d.ts +5 -0
  57. package/dist/testing/reporters/json.js +23 -0
  58. package/dist/testing/reporters/junit.d.ts +5 -0
  59. package/dist/testing/reporters/junit.js +31 -0
  60. package/dist/testing/reporters/text.d.ts +5 -0
  61. package/dist/testing/reporters/text.js +36 -0
  62. package/dist/testing/runner.d.ts +25 -0
  63. package/dist/testing/runner.js +222 -0
  64. package/dist/testing/spec-parser.d.ts +366 -0
  65. package/dist/testing/spec-parser.js +60 -0
  66. package/dist/testing/stage-extractor.d.ts +16 -0
  67. package/dist/testing/stage-extractor.js +25 -0
  68. package/dist/tools/audio-transcribe.d.ts +11 -0
  69. package/dist/tools/audio-transcribe.js +45 -0
  70. package/dist/tools/image-describe.d.ts +12 -0
  71. package/dist/tools/image-describe.js +47 -0
  72. package/dist/tools/image-generate.d.ts +12 -0
  73. package/dist/tools/image-generate.js +47 -0
  74. package/dist/tools/memory-recall.d.ts +13 -0
  75. package/dist/tools/memory-recall.js +63 -0
  76. package/dist/tools/memory-shared.d.ts +8 -0
  77. package/dist/tools/memory-shared.js +8 -0
  78. package/dist/tools/memory-store.d.ts +14 -0
  79. package/dist/tools/memory-store.js +68 -0
  80. package/dist/tools/tool-skills.js +14 -0
  81. package/dist/tools/tts-synthesize.d.ts +12 -0
  82. package/dist/tools/tts-synthesize.js +50 -0
  83. package/dist/tools/video-generate.d.ts +12 -0
  84. package/dist/tools/video-generate.js +47 -0
  85. package/dist/types.d.ts +8 -0
  86. package/dist/validate-inputs.d.ts +115 -0
  87. package/dist/validate-inputs.js +273 -0
  88. package/dist/webhook.js +0 -0
  89. package/package.json +3 -3
@@ -0,0 +1,63 @@
1
+ import { getStoreForAgent } from './memory-shared.js';
2
+ function getStore(ctx) {
3
+ return getStoreForAgent(ctx);
4
+ }
5
+ export async function memoryRecallHandler(input, ctx) {
6
+ const parsed = parseInput(input);
7
+ const enabled = globalThis
8
+ .process?.env?.MEMORY_ENABLED === 'true';
9
+ if (!enabled) {
10
+ return mockResult(parsed);
11
+ }
12
+ return realStoreCall(parsed, getStore(ctx));
13
+ }
14
+ function parseInput(input) {
15
+ if (typeof input !== 'object' || input === null) {
16
+ throw new Error('memory_recall requires object input with pipeline_id + partition');
17
+ }
18
+ const obj = input;
19
+ const pipeline_id = obj.pipeline_id;
20
+ const partition = obj.partition;
21
+ if (typeof pipeline_id !== 'string' || pipeline_id.length === 0) {
22
+ throw new Error('memory_recall: pipeline_id is required');
23
+ }
24
+ if (typeof partition !== 'string' || partition.length === 0) {
25
+ throw new Error('memory_recall: partition is required');
26
+ }
27
+ return {
28
+ pipeline_id,
29
+ partition,
30
+ key: typeof obj.key === 'string' ? obj.key : undefined,
31
+ prefix: typeof obj.prefix === 'string' ? obj.prefix : undefined,
32
+ };
33
+ }
34
+ function makePartition(parsed) {
35
+ return { pipeline_id: parsed.pipeline_id, partition: parsed.partition, scope: 'pipeline' };
36
+ }
37
+ function mockResult(parsed) {
38
+ const text = parsed.key !== undefined
39
+ ? JSON.stringify({ ok: true, mock: true, key: parsed.key, value: null, reason: 'memory_recall mock-mode' })
40
+ : JSON.stringify({ ok: true, mock: true, keys: [], reason: 'memory_recall mock-mode' });
41
+ return {
42
+ text,
43
+ usage: { inputTokens: 0, outputTokens: 0 },
44
+ meta: { tool: 'memory_recall', mode: 'mock' },
45
+ };
46
+ }
47
+ async function realStoreCall(parsed, store) {
48
+ const partition = makePartition(parsed);
49
+ if (parsed.key !== undefined) {
50
+ const value = await store.get(partition, parsed.key);
51
+ return {
52
+ text: JSON.stringify({ ok: true, key: parsed.key, value }),
53
+ usage: { inputTokens: 0, outputTokens: 0 },
54
+ meta: { tool: 'memory_recall' },
55
+ };
56
+ }
57
+ const keys = await store.list(partition, parsed.prefix);
58
+ return {
59
+ text: JSON.stringify({ ok: true, keys, prefix: parsed.prefix ?? '' }),
60
+ usage: { inputTokens: 0, outputTokens: 0 },
61
+ meta: { tool: 'memory_recall' },
62
+ };
63
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * memory-shared — shared in-memory store cache for memory tool skills.
3
+ * Single globalStoreCache Map used by both memory_store and memory_recall
4
+ * so cross-module store → recall round-trips share state per agent.
5
+ */
6
+ import type { ToolSkillContext } from './tool-skills.js';
7
+ import type { MemoryStore } from '../memory.js';
8
+ export declare function getStoreForAgent(ctx: ToolSkillContext): MemoryStore;
@@ -0,0 +1,8 @@
1
+ import { InMemoryMemoryStore } from '../memory.js';
2
+ const globalStoreCache = new Map();
3
+ export function getStoreForAgent(ctx) {
4
+ if (!globalStoreCache.has(ctx.agentId)) {
5
+ globalStoreCache.set(ctx.agentId, new InMemoryMemoryStore());
6
+ }
7
+ return globalStoreCache.get(ctx.agentId);
8
+ }
@@ -0,0 +1,14 @@
1
+ /**
2
+ * memory_store — tool skill (M6.1).
3
+ * Write a value to a pipeline memory partition (with optional TTL).
4
+ * Mock-mode default unless MEMORY_ENABLED=true (requires R2 binding).
5
+ */
6
+ import type { ToolSkillContext, ToolSkillResult } from './tool-skills.js';
7
+ export interface MemoryStoreInput {
8
+ pipeline_id: string;
9
+ partition: string;
10
+ key: string;
11
+ value: unknown;
12
+ ttl_seconds?: number;
13
+ }
14
+ export declare function memoryStoreHandler(input: unknown, ctx: ToolSkillContext): Promise<ToolSkillResult>;
@@ -0,0 +1,68 @@
1
+ import { getStoreForAgent } from './memory-shared.js';
2
+ function getStore(ctx) {
3
+ return getStoreForAgent(ctx);
4
+ }
5
+ export async function memoryStoreHandler(input, ctx) {
6
+ const parsed = parseInput(input);
7
+ const enabled = globalThis
8
+ .process?.env?.MEMORY_ENABLED === 'true';
9
+ if (!enabled) {
10
+ return mockResult(parsed);
11
+ }
12
+ return realStoreCall(parsed, getStore(ctx));
13
+ }
14
+ function parseInput(input) {
15
+ if (typeof input !== 'object' || input === null) {
16
+ throw new Error('memory_store requires object input with pipeline_id + partition + key + value');
17
+ }
18
+ const obj = input;
19
+ const pipeline_id = obj.pipeline_id;
20
+ const partition = obj.partition;
21
+ const key = obj.key;
22
+ if (typeof pipeline_id !== 'string' || pipeline_id.length === 0) {
23
+ throw new Error('memory_store: pipeline_id is required');
24
+ }
25
+ if (typeof partition !== 'string' || partition.length === 0) {
26
+ throw new Error('memory_store: partition is required');
27
+ }
28
+ if (typeof key !== 'string' || key.length === 0) {
29
+ throw new Error('memory_store: key is required and non-empty');
30
+ }
31
+ if (!('value' in obj)) {
32
+ throw new Error('memory_store: value is required (any JSON-serializable)');
33
+ }
34
+ return {
35
+ pipeline_id,
36
+ partition,
37
+ key,
38
+ value: obj.value,
39
+ ttl_seconds: typeof obj.ttl_seconds === 'number' && obj.ttl_seconds > 0 ? obj.ttl_seconds : undefined,
40
+ };
41
+ }
42
+ function mockResult(parsed) {
43
+ return {
44
+ text: JSON.stringify({
45
+ ok: true,
46
+ mock: true,
47
+ key: parsed.key,
48
+ stored_at: new Date().toISOString(),
49
+ reason: 'memory_store mock-mode',
50
+ }),
51
+ usage: { inputTokens: 0, outputTokens: 0 },
52
+ meta: { tool: 'memory_store', mode: 'mock' },
53
+ };
54
+ }
55
+ async function realStoreCall(parsed, store) {
56
+ const partition = { pipeline_id: parsed.pipeline_id, partition: parsed.partition, scope: 'pipeline' };
57
+ await store.set(partition, parsed.key, parsed.value, parsed.ttl_seconds);
58
+ return {
59
+ text: JSON.stringify({
60
+ ok: true,
61
+ key: parsed.key,
62
+ stored_at: new Date().toISOString(),
63
+ ttl_seconds: parsed.ttl_seconds ?? null,
64
+ }),
65
+ usage: { inputTokens: 0, outputTokens: 0 },
66
+ meta: { tool: 'memory_store' },
67
+ };
68
+ }
@@ -15,8 +15,22 @@
15
15
  *
16
16
  * Add new tools here as the catalog grows.
17
17
  */
18
+ import { imageDescribeHandler } from './image-describe.js';
19
+ import { audioTranscribeHandler } from './audio-transcribe.js';
20
+ import { ttsSynthesizeHandler } from './tts-synthesize.js';
21
+ import { imageGenerateHandler } from './image-generate.js';
22
+ import { videoGenerateHandler } from './video-generate.js';
23
+ import { memoryRecallHandler } from './memory-recall.js';
24
+ import { memoryStoreHandler } from './memory-store.js';
18
25
  const TOOL_SKILLS = {
19
26
  web_fetch: webFetchHandler,
27
+ image_describe: imageDescribeHandler,
28
+ audio_transcribe: audioTranscribeHandler,
29
+ tts_synthesize: ttsSynthesizeHandler,
30
+ image_generate: imageGenerateHandler,
31
+ video_generate: videoGenerateHandler,
32
+ memory_recall: memoryRecallHandler,
33
+ memory_store: memoryStoreHandler,
20
34
  };
21
35
  export function isToolSkill(skillId) {
22
36
  return skillId in TOOL_SKILLS;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * tts_synthesize — tool skill (M2).
3
+ * Text-to-speech via ElevenLabs / OpenAI TTS. Mock-mode default unless
4
+ * TOOL_SKILL_TTS_SYNTHESIZE_ENABLED=true (requires provider API key).
5
+ */
6
+ import type { ToolSkillContext, ToolSkillResult } from './tool-skills.js';
7
+ export interface TTSSynthesizeInput {
8
+ text: string;
9
+ voice?: string;
10
+ format?: 'mp3' | 'wav' | 'opus';
11
+ }
12
+ export declare function ttsSynthesizeHandler(input: unknown, ctx: ToolSkillContext): Promise<ToolSkillResult>;
@@ -0,0 +1,50 @@
1
+ import { openaiTtsSynthesize } from '../providers/openai-tts.js';
2
+ const MAX_CHARS = 5000;
3
+ export async function ttsSynthesizeHandler(input, ctx) {
4
+ const parsed = parseInput(input);
5
+ const enabled = globalThis
6
+ .process?.env?.TOOL_SKILL_TTS_SYNTHESIZE_ENABLED === 'true';
7
+ if (!enabled) {
8
+ return mockResult(parsed);
9
+ }
10
+ return realProviderCall(parsed, ctx);
11
+ }
12
+ function parseInput(input) {
13
+ if (typeof input !== 'object' || input === null) {
14
+ throw new Error('tts_synthesize requires object input with text');
15
+ }
16
+ const obj = input;
17
+ const text = obj.text;
18
+ if (typeof text !== 'string' || text.length === 0) {
19
+ throw new Error('tts_synthesize: text is required and non-empty');
20
+ }
21
+ if (text.length > MAX_CHARS) {
22
+ throw new Error(`tts_synthesize: text exceeds max ${MAX_CHARS} chars (got ${text.length})`);
23
+ }
24
+ return {
25
+ text,
26
+ voice: typeof obj.voice === 'string' ? obj.voice : 'alloy',
27
+ format: obj.format === 'wav' || obj.format === 'opus' ? obj.format : 'mp3',
28
+ };
29
+ }
30
+ function mockResult(parsed) {
31
+ return {
32
+ text: JSON.stringify({
33
+ ok: true,
34
+ mock: true,
35
+ audio_url: 'mock://tts/' + Math.random().toString(36).slice(2, 10),
36
+ format: parsed.format,
37
+ voice: parsed.voice,
38
+ duration_seconds: Math.ceil(parsed.text.length / 15),
39
+ }),
40
+ usage: { inputTokens: 0, outputTokens: 0 },
41
+ meta: { tool: 'tts_synthesize', mode: 'mock' },
42
+ };
43
+ }
44
+ async function realProviderCall(parsed, _ctx) {
45
+ return openaiTtsSynthesize({
46
+ text: parsed.text,
47
+ voice: (parsed.voice ?? 'alloy'),
48
+ format: (parsed.format ?? 'mp3'),
49
+ });
50
+ }
@@ -0,0 +1,12 @@
1
+ /**
2
+ * video_generate — tool skill (M2).
3
+ * Text-to-video via Runway / Pika. Async polling pattern.
4
+ * Mock-mode default unless TOOL_SKILL_VIDEO_GENERATE_ENABLED=true.
5
+ */
6
+ import type { ToolSkillContext, ToolSkillResult } from './tool-skills.js';
7
+ export interface VideoGenerateInput {
8
+ prompt: string;
9
+ duration_seconds?: number;
10
+ resolution?: '720p' | '1080p';
11
+ }
12
+ export declare function videoGenerateHandler(input: unknown, ctx: ToolSkillContext): Promise<ToolSkillResult>;
@@ -0,0 +1,47 @@
1
+ import { replicateGenerateVideo } from '../providers/replicate.js';
2
+ const MAX_DURATION = 30;
3
+ export async function videoGenerateHandler(input, ctx) {
4
+ const parsed = parseInput(input);
5
+ const enabled = globalThis
6
+ .process?.env?.TOOL_SKILL_VIDEO_GENERATE_ENABLED === 'true';
7
+ if (!enabled) {
8
+ return mockResult(parsed);
9
+ }
10
+ return realProviderCall(parsed, ctx);
11
+ }
12
+ function parseInput(input) {
13
+ if (typeof input !== 'object' || input === null) {
14
+ throw new Error('video_generate requires object input with prompt');
15
+ }
16
+ const obj = input;
17
+ const prompt = obj.prompt;
18
+ if (typeof prompt !== 'string' || prompt.length === 0) {
19
+ throw new Error('video_generate: prompt is required and non-empty');
20
+ }
21
+ const duration = typeof obj.duration_seconds === 'number' && obj.duration_seconds > 0
22
+ ? Math.min(obj.duration_seconds, MAX_DURATION)
23
+ : 4;
24
+ const resolution = obj.resolution === '1080p' ? '1080p' : '720p';
25
+ return { prompt, duration_seconds: duration, resolution };
26
+ }
27
+ function mockResult(parsed) {
28
+ return {
29
+ text: JSON.stringify({
30
+ ok: true,
31
+ mock: true,
32
+ video_url: `mock://video-gen/${Date.now()}.mp4`,
33
+ duration_seconds: parsed.duration_seconds,
34
+ resolution: parsed.resolution,
35
+ status: 'completed',
36
+ }),
37
+ usage: { inputTokens: 0, outputTokens: 0 },
38
+ meta: { tool: 'video_generate', mode: 'mock' },
39
+ };
40
+ }
41
+ async function realProviderCall(parsed, _ctx) {
42
+ return replicateGenerateVideo({
43
+ prompt: parsed.prompt,
44
+ duration_seconds: parsed.duration_seconds,
45
+ resolution: parsed.resolution === '1080p' ? '1080p' : '720p',
46
+ });
47
+ }
package/dist/types.d.ts CHANGED
@@ -7,6 +7,7 @@
7
7
  * This indirection lets us swap providers (MiniMax -> Claude -> OpenAI) without
8
8
  * changing Pipeline specs.
9
9
  */
10
+ import type { MultimodalMessage } from './multimodal.js';
10
11
  export type Complexity = 'simple' | 'complex';
11
12
  export interface GenerateOptions {
12
13
  /** 'simple' uses simpleModel, 'complex' uses complexModel. Default: 'simple'. */
@@ -53,6 +54,13 @@ export interface GenerateOptions {
53
54
  * demo/QA without a real LLM.
54
55
  */
55
56
  outputFormat?: OutputFormat;
57
+ /**
58
+ * M1 NEW — Multimodal messages (image / audio / video parts). When set,
59
+ * takes precedence over the string `prompt` argument. Adapters transform
60
+ * this to the provider-native request body. Must target a vision-capable
61
+ * model — see provider-registry.ts `visionCapableModels`.
62
+ */
63
+ messages?: readonly MultimodalMessage[];
56
64
  }
57
65
  export interface TokenUsage {
58
66
  inputTokens: number;
@@ -21,7 +21,13 @@
21
21
  * spec.inputs is missing or input has extra keys). Permissiveness on the
22
22
  * "extra" axis avoids breaking ad-hoc CLI invocations; strictness is only
23
23
  * on the "missing required" axis.
24
+ *
25
+ * M5 — `validateOutput()` is the symmetric output validator (server-side
26
+ * stage output validation against JSON Schema). Returns structured
27
+ * violations the executor uses to drive retry modes (none|single|loop).
24
28
  */
29
+ import type { JsonSchema, OutputValidationResult, OutputValidationViolation } from './output-schema.js';
30
+ import type { MultimodalMessage } from './multimodal.js';
25
31
  export interface InputDecl {
26
32
  type?: 'string' | 'integer' | 'number' | 'boolean' | 'array' | 'object';
27
33
  required?: boolean;
@@ -41,3 +47,112 @@ export interface InputValidationError {
41
47
  }
42
48
  export declare function validateInputs(specInputs: InputSpec | undefined, provided: Record<string, unknown>): InputValidationError[];
43
49
  export declare function formatInputErrors(errors: InputValidationError[], inputs?: InputSpec): string;
50
+ export interface ValidateOutputOptions {
51
+ parseJson?: boolean;
52
+ }
53
+ export type ValidateOutputResult = {
54
+ ok: true;
55
+ value: unknown;
56
+ } | {
57
+ ok: false;
58
+ violations: OutputValidationViolation[];
59
+ schemaError?: OutputValidationResult;
60
+ };
61
+ export declare function validateOutput(rawOutput: string, schema: JsonSchema, opts?: ValidateOutputOptions): ValidateOutputResult;
62
+ /**
63
+ * Strip a wrapping markdown code fence.
64
+ *
65
+ * A model asked for JSON routinely answers ```json … ``` no matter how
66
+ * plainly the prompt says not to. The generateJson paths have always coped —
67
+ * adapters/minimax.ts, adapters/openrouter.ts, providers/anthropic.ts and
68
+ * providers/openai-chat.ts each carried the same two-line regex — but the two
69
+ * output validators parsed the raw text. So a fenced answer failed
70
+ * `output_format: structured_json` and `output_schema` validation while the
71
+ * identical string parsed fine through generateJson, which is why every
72
+ * structured-output stage was exposed to this.
73
+ *
74
+ * Deliberately conservative: it only acts when the text actually begins with a
75
+ * fence, so prose that merely mentions backticks is untouched. Accepts a fence
76
+ * with a language tag or none, and an unterminated one.
77
+ */
78
+ export declare function stripJsonFence(text: string): string;
79
+ /**
80
+ * The first balanced `{...}` / `[...]` region in `text`, or null if there is
81
+ * none. Brace counting respects string literals and escapes, so a `{` inside a
82
+ * JSON string value cannot throw the scan off.
83
+ *
84
+ * This exists because `stripJsonFence` requires the text to *begin* with a fence,
85
+ * which is a reasonable guard against prose that merely mentions backticks — but
86
+ * it misses the case production actually hit twice: the model answering
87
+ *
88
+ * Here is the JSON you asked for:
89
+ * ```json
90
+ * { ... }
91
+ * ```
92
+ *
93
+ * Prose, then a fence. Not stripped, so `JSON.parse` died on the backtick and
94
+ * the whole run failed. Measured in prod before this: 2 runs on exactly that
95
+ * shape, 2 more on prose with no fence at all.
96
+ */
97
+ export declare function extractJsonRegion(text: string): string | null;
98
+ /** Drop `,` that sits immediately before a closing brace/bracket.
99
+ *
100
+ * String-aware, so a comma inside a value is never touched. */
101
+ export declare function removeTrailingCommas(json: string): string;
102
+ /**
103
+ * Max recursion depth for unwrapping double-encoded JSON. Models occasionally
104
+ * emit a JSON object as a STRING value (i.e. the answer is a quoted JSON
105
+ * document), which the strict parser sees as a plain string. Three levels is
106
+ * enough to cover the realistic case — one accidental re-quoting, maybe two —
107
+ * without turning a missing-bracket case into an infinite loop.
108
+ */
109
+ export declare const MAX_DOUBLE_UNWRAP_DEPTH = 3;
110
+ /**
111
+ * If `value` is a string that itself parses strictly as JSON, return the inner
112
+ * parsed value. Otherwise return `value` unchanged. Bounded depth so a
113
+ * pathological input cannot loop forever.
114
+ *
115
+ * Safety property — same shape as `parseJsonLenient`. The inner parse is
116
+ * strict: a string that does not parse is left as a string, and only the
117
+ * outermost string is "unwrapped" — there is no reshaping of structure, no
118
+ * invented keys, no coercion of numbers/booleans/null. A single level of
119
+ * unwrap is the common case; deeper levels only fire if each step strictly
120
+ * parses.
121
+ */
122
+ export declare function unwrapDoubleEncoded(value: unknown, depth?: number): unknown;
123
+ /**
124
+ * Parse JSON a model produced, tolerating the wrappers it actually adds.
125
+ *
126
+ * Strict parse first, and every fallback is only accepted if it parses strictly.
127
+ * That ordering is the whole safety argument: valid JSON is returned untouched,
128
+ * and anything unparseable still throws the ORIGINAL error from the strict
129
+ * attempt, so nothing is silently reshaped into "valid" and the error still
130
+ * points at what the model really said.
131
+ *
132
+ * Deliberately NOT attempted: rewriting quotes, adding missing braces, or
133
+ * coercing unquoted keys. Those change the meaning of string content, and a
134
+ * marketplace that guesses at a buyer's data is worse than one that fails.
135
+ *
136
+ * Production, before this existed, also failed on JSON that the model emitted
137
+ * as a quoted string — `"{\"summary\": \"...\"}"`. Strict parse returned a
138
+ * plain string, the schema asked for an object, and the run died with
139
+ * "$: expected type object, got string". `unwrapDoubleEncoded` unpacks such a
140
+ * shape recursively up to `MAX_DOUBLE_UNWRAP_DEPTH`, only ever when the inner
141
+ * parse is strict. This is unwrapping, not invention: the value the model
142
+ * returned is byte-for-byte the same JSON document, just wrapped one extra
143
+ * time in quotes.
144
+ */
145
+ export declare function parseJsonLenient(text: string): unknown;
146
+ export interface MultimodalValidationError {
147
+ messageIndex: number;
148
+ partIndex?: number;
149
+ reason: 'empty_content' | 'invalid_role' | 'invalid_url' | 'unsupported_mime' | 'unsupported_scheme';
150
+ detail?: string;
151
+ }
152
+ export type MultimodalValidationResult = {
153
+ ok: true;
154
+ } | {
155
+ ok: false;
156
+ errors: MultimodalValidationError[];
157
+ };
158
+ export declare function validateMultimodalInput(messages: readonly MultimodalMessage[]): MultimodalValidationResult;