@warlock.js/ai 4.5.0 → 4.6.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 (159) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/cjs/index.cjs +20 -1
  3. package/cjs/{src-DFibP2FQ.cjs → src-Bmajk4Qg.cjs} +1 -1
  4. package/cjs/{src-C02yzsLs.cjs → src-OZyDYHxm.cjs} +2789 -691
  5. package/cjs/src-OZyDYHxm.cjs.map +1 -0
  6. package/esm/agent/agent-config.type.d.mts +29 -0
  7. package/esm/agent/agent-config.type.d.mts.map +1 -1
  8. package/esm/agent/agent.d.mts.map +1 -1
  9. package/esm/agent/agent.mjs +126 -7
  10. package/esm/agent/agent.mjs.map +1 -1
  11. package/esm/agent/signature.mjs +57 -0
  12. package/esm/agent/signature.mjs.map +1 -0
  13. package/esm/agent/snapshot.mjs +101 -0
  14. package/esm/agent/snapshot.mjs.map +1 -0
  15. package/esm/ai-openai/src/image.mjs +5 -0
  16. package/esm/ai-openai/src/index.mjs +3 -0
  17. package/esm/ai-openai/src/sdk.mjs +3 -0
  18. package/esm/ai-openai/src/speech.mjs +5 -0
  19. package/esm/ai-openai/src/transcription.mjs +6 -0
  20. package/esm/ai-openai/src/utils/index.mjs +1 -0
  21. package/esm/ai-openai/src/utils/to-openai-messages.mjs +3 -0
  22. package/esm/ai.d.mts +45 -0
  23. package/esm/ai.d.mts.map +1 -1
  24. package/esm/ai.mjs +37 -1
  25. package/esm/ai.mjs.map +1 -1
  26. package/esm/contracts/agent/agent-options.type.d.mts +22 -2
  27. package/esm/contracts/agent/agent-options.type.d.mts.map +1 -1
  28. package/esm/contracts/agent/agent-snapshot.type.d.mts +90 -0
  29. package/esm/contracts/agent/agent-snapshot.type.d.mts.map +1 -0
  30. package/esm/contracts/agent/agent.contract.d.mts +29 -1
  31. package/esm/contracts/agent/agent.contract.d.mts.map +1 -1
  32. package/esm/contracts/agent/index.d.mts +2 -1
  33. package/esm/contracts/image-model.contract.d.mts +156 -0
  34. package/esm/contracts/image-model.contract.d.mts.map +1 -0
  35. package/esm/contracts/index.d.mts +8 -3
  36. package/esm/contracts/planner/index.d.mts +3 -2
  37. package/esm/contracts/planner/planner-config.type.d.mts +30 -0
  38. package/esm/contracts/planner/planner-config.type.d.mts.map +1 -1
  39. package/esm/contracts/planner/planner-execute-options.type.d.mts +13 -1
  40. package/esm/contracts/planner/planner-execute-options.type.d.mts.map +1 -1
  41. package/esm/contracts/planner/planner-snapshot.type.d.mts +77 -0
  42. package/esm/contracts/planner/planner-snapshot.type.d.mts.map +1 -0
  43. package/esm/contracts/planner/planner.contract.d.mts +21 -1
  44. package/esm/contracts/planner/planner.contract.d.mts.map +1 -1
  45. package/esm/contracts/result/base-report.type.d.mts +1 -1
  46. package/esm/contracts/result/base-report.type.d.mts.map +1 -1
  47. package/esm/contracts/result/base-report.type.mjs.map +1 -1
  48. package/esm/contracts/sdk-adapter.contract.d.mts +37 -0
  49. package/esm/contracts/sdk-adapter.contract.d.mts.map +1 -1
  50. package/esm/contracts/speech-model.contract.d.mts +97 -0
  51. package/esm/contracts/speech-model.contract.d.mts.map +1 -0
  52. package/esm/contracts/transcription-model.contract.d.mts +101 -0
  53. package/esm/contracts/transcription-model.contract.d.mts.map +1 -0
  54. package/esm/errors/agent-drift-error.d.mts +32 -0
  55. package/esm/errors/agent-drift-error.d.mts.map +1 -0
  56. package/esm/errors/agent-drift-error.mjs +31 -0
  57. package/esm/errors/agent-drift-error.mjs.map +1 -0
  58. package/esm/errors/error-code.type.d.mts +1 -1
  59. package/esm/errors/index.d.mts +2 -0
  60. package/esm/errors/index.mjs +2 -0
  61. package/esm/errors/planner-drift-error.d.mts +34 -0
  62. package/esm/errors/planner-drift-error.d.mts.map +1 -0
  63. package/esm/errors/planner-drift-error.mjs +33 -0
  64. package/esm/errors/planner-drift-error.mjs.map +1 -0
  65. package/esm/image/image-cost.d.mts +32 -0
  66. package/esm/image/image-cost.d.mts.map +1 -0
  67. package/esm/image/image-cost.mjs +55 -0
  68. package/esm/image/image-cost.mjs.map +1 -0
  69. package/esm/image/image.d.mts +92 -0
  70. package/esm/image/image.d.mts.map +1 -0
  71. package/esm/image/image.mjs +113 -0
  72. package/esm/image/image.mjs.map +1 -0
  73. package/esm/image/index.mjs +4 -0
  74. package/esm/index.d.mts +26 -4
  75. package/esm/index.mjs +20 -1
  76. package/esm/mock/index.d.mts +3 -0
  77. package/esm/mock/index.mjs +3 -0
  78. package/esm/mock/mock-config.type.d.mts +22 -0
  79. package/esm/mock/mock-config.type.d.mts.map +1 -1
  80. package/esm/mock/mock-image-model.d.mts +41 -0
  81. package/esm/mock/mock-image-model.d.mts.map +1 -0
  82. package/esm/mock/mock-image-model.mjs +52 -0
  83. package/esm/mock/mock-image-model.mjs.map +1 -0
  84. package/esm/mock/mock-sdk.d.mts +7 -1
  85. package/esm/mock/mock-sdk.d.mts.map +1 -1
  86. package/esm/mock/mock-sdk.mjs +27 -0
  87. package/esm/mock/mock-sdk.mjs.map +1 -1
  88. package/esm/mock/mock-speech-model.d.mts +31 -0
  89. package/esm/mock/mock-speech-model.d.mts.map +1 -0
  90. package/esm/mock/mock-speech-model.mjs +39 -0
  91. package/esm/mock/mock-speech-model.mjs.map +1 -0
  92. package/esm/mock/mock-transcription-model.d.mts +32 -0
  93. package/esm/mock/mock-transcription-model.d.mts.map +1 -0
  94. package/esm/mock/mock-transcription-model.mjs +36 -0
  95. package/esm/mock/mock-transcription-model.mjs.map +1 -0
  96. package/esm/planner/planner-run.d.mts +8 -0
  97. package/esm/planner/planner-run.d.mts.map +1 -1
  98. package/esm/planner/planner-run.mjs +161 -6
  99. package/esm/planner/planner-run.mjs.map +1 -1
  100. package/esm/planner/planner.d.mts.map +1 -1
  101. package/esm/planner/planner.mjs +25 -1
  102. package/esm/planner/planner.mjs.map +1 -1
  103. package/esm/planner/snapshot.mjs +95 -0
  104. package/esm/planner/snapshot.mjs.map +1 -0
  105. package/esm/rag/index.d.mts +7 -0
  106. package/esm/rag/index.mjs +7 -0
  107. package/esm/rag/loaders/errors.d.mts +19 -0
  108. package/esm/rag/loaders/errors.d.mts.map +1 -0
  109. package/esm/rag/loaders/errors.mjs +25 -0
  110. package/esm/rag/loaders/errors.mjs.map +1 -0
  111. package/esm/rag/loaders/index.mjs +7 -0
  112. package/esm/rag/loaders/load-html.d.mts +26 -0
  113. package/esm/rag/loaders/load-html.d.mts.map +1 -0
  114. package/esm/rag/loaders/load-html.mjs +138 -0
  115. package/esm/rag/loaders/load-html.mjs.map +1 -0
  116. package/esm/rag/loaders/load-pdf.d.mts +38 -0
  117. package/esm/rag/loaders/load-pdf.d.mts.map +1 -0
  118. package/esm/rag/loaders/load-pdf.mjs +150 -0
  119. package/esm/rag/loaders/load-pdf.mjs.map +1 -0
  120. package/esm/rag/loaders/load-text.d.mts +47 -0
  121. package/esm/rag/loaders/load-text.d.mts.map +1 -0
  122. package/esm/rag/loaders/load-text.mjs +60 -0
  123. package/esm/rag/loaders/load-text.mjs.map +1 -0
  124. package/esm/rag/loaders/load-web.d.mts +42 -0
  125. package/esm/rag/loaders/load-web.d.mts.map +1 -0
  126. package/esm/rag/loaders/load-web.mjs +89 -0
  127. package/esm/rag/loaders/load-web.mjs.map +1 -0
  128. package/esm/rag/loaders/loader.type.d.mts +89 -0
  129. package/esm/rag/loaders/loader.type.d.mts.map +1 -0
  130. package/esm/rag/store/pg-vector-store.d.mts +139 -0
  131. package/esm/rag/store/pg-vector-store.d.mts.map +1 -0
  132. package/esm/rag/store/pg-vector-store.mjs +328 -0
  133. package/esm/rag/store/pg-vector-store.mjs.map +1 -0
  134. package/esm/speech/index.mjs +3 -0
  135. package/esm/speech/speech.d.mts +65 -0
  136. package/esm/speech/speech.d.mts.map +1 -0
  137. package/esm/speech/speech.mjs +123 -0
  138. package/esm/speech/speech.mjs.map +1 -0
  139. package/esm/supervisor/entries.mjs +2 -2
  140. package/esm/supervisor/entries.mjs.map +1 -1
  141. package/esm/transcribe/audio-input.d.mts +47 -0
  142. package/esm/transcribe/audio-input.d.mts.map +1 -0
  143. package/esm/transcribe/audio-input.mjs +84 -0
  144. package/esm/transcribe/audio-input.mjs.map +1 -0
  145. package/esm/transcribe/index.mjs +4 -0
  146. package/esm/transcribe/transcribe.d.mts +64 -0
  147. package/esm/transcribe/transcribe.d.mts.map +1 -0
  148. package/esm/transcribe/transcribe.mjs +128 -0
  149. package/esm/transcribe/transcribe.mjs.map +1 -0
  150. package/llms-full.txt +753 -0
  151. package/llms.txt +5 -0
  152. package/package.json +3 -3
  153. package/skills/README.md +4 -0
  154. package/skills/durable-agent-runs/SKILL.md +135 -0
  155. package/skills/generate-images/SKILL.md +138 -0
  156. package/skills/generate-speech/SKILL.md +139 -0
  157. package/skills/rag-loaders-and-stores/SKILL.md +164 -0
  158. package/skills/transcribe-audio/SKILL.md +157 -0
  159. package/cjs/src-C02yzsLs.cjs.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"snapshot.mjs","names":[],"sources":["../../../../../../../@warlock.js/ai/src/agent/snapshot.ts"],"sourcesContent":["import { resolveDefaultSnapshotStore } from \"../config\";\nimport type {\n AgentResumeOptions,\n} from \"../contracts/agent/agent-options.type\";\nimport type {\n AgentSnapshot,\n AgentSnapshotStatus,\n} from \"../contracts/agent/agent-snapshot.type\";\nimport type { SnapshotStore } from \"../contracts/orchestrator/snapshot-store.contract\";\nimport type { Message } from \"../contracts/conversation-message.type\";\nimport type { LLMTrip } from \"../contracts/result/llm-trip.type\";\nimport type { ToolCall } from \"../contracts/result/tool-call.type\";\nimport type { Usage } from \"../contracts/result/usage.type\";\nimport { AgentDriftError, AgentExecutionError } from \"../errors\";\n\n/**\n * The agent's `durable` config, narrowed to the fields the snapshot\n * helpers read. Kept minimal so this module doesn't depend on the full\n * resolved-config shape.\n */\nexport type AgentDurableConfig = {\n store?: SnapshotStore<AgentSnapshot>;\n deleteOnComplete?: boolean;\n};\n\n/**\n * Resolve the effective {@link SnapshotStore}: the agent's own\n * `durable.store` wins; absent that, fall back to the global default\n * set via `ai.config({ defaultSnapshotStore })`.\n *\n * The global default is typed for the supervisor snapshot shape, but\n * every store impl keys purely by `runId` and round-trips whatever\n * envelope it is handed — so it serves an `AgentSnapshot` just as well.\n * The cast re-tags the shape at this single boundary (Option B); the\n * agent only ever hands it an `AgentSnapshot`.\n */\nfunction resolveSnapshotStore(\n durable: AgentDurableConfig | undefined,\n): SnapshotStore<AgentSnapshot> | undefined {\n return (\n durable?.store ??\n (resolveDefaultSnapshotStore() as SnapshotStore<AgentSnapshot> | undefined)\n );\n}\n\nexport type PersistAgentParams = {\n durable: AgentDurableConfig | undefined;\n runId: string;\n agentName: string;\n signature: string;\n version?: string;\n input: string;\n systemPrompt?: string;\n responseSchema?: Record<string, unknown>;\n promptName?: string;\n promptVersion?: string;\n messages: Message[];\n trips: LLMTrip[];\n toolCalls: ToolCall[];\n usage: Usage;\n status: AgentSnapshotStatus;\n startedAt: string;\n};\n\nexport type PersistOutcome = { ok: true } | { ok: false; error: unknown };\n\n/**\n * Write the current run state to the resolved snapshot store. No-op\n * (returns `{ ok: true }`) when neither `durable.store` nor the global\n * `defaultSnapshotStore` is configured — the common non-durable path.\n * Failures are returned as `{ ok: false }` rather than thrown so the\n * engine can surface them via logs without aborting the run — a failed\n * checkpoint loses resume-ability from that point but never breaks an\n * otherwise-healthy run.\n */\nexport async function persistAgentSnapshot(\n params: PersistAgentParams,\n): Promise<PersistOutcome> {\n const store = resolveSnapshotStore(params.durable);\n\n if (!store) {\n return { ok: true };\n }\n\n const snapshot: AgentSnapshot = {\n runId: params.runId,\n agentName: params.agentName,\n signature: params.signature,\n version: params.version,\n input: params.input,\n systemPrompt: params.systemPrompt,\n responseSchema: params.responseSchema,\n promptName: params.promptName,\n promptVersion: params.promptVersion,\n messages: params.messages,\n trips: params.trips,\n toolCalls: params.toolCalls,\n usage: params.usage,\n status: params.status,\n startedAt: params.startedAt,\n savedAt: new Date().toISOString(),\n };\n\n try {\n await store.save(snapshot);\n\n return { ok: true };\n } catch (error) {\n return { ok: false, error };\n }\n}\n\n/**\n * Delete a persisted snapshot — used after a successful run when\n * `durable.deleteOnComplete` is set. Never throws: a failed delete is\n * surfaced as `{ ok: false }` and the engine logs it. No-op (ok) when no\n * store is configured.\n */\nexport async function deleteAgentSnapshot(params: {\n durable: AgentDurableConfig | undefined;\n runId: string;\n}): Promise<PersistOutcome> {\n const store = resolveSnapshotStore(params.durable);\n\n if (!store) {\n return { ok: true };\n }\n\n try {\n await store.delete(params.runId);\n\n return { ok: true };\n } catch (error) {\n return { ok: false, error };\n }\n}\n\n/**\n * Load a persisted snapshot for `resume()` and run the drift check.\n * Throws `AgentExecutionError` when no store is configured or when the\n * run is missing; throws `AgentDriftError` when the stored signature\n * doesn't match the current definition (unless `force` is set).\n */\nexport async function loadAgentSnapshotForResume(params: {\n durable: AgentDurableConfig | undefined;\n agentName: string;\n signature: string;\n runId: string;\n options?: AgentResumeOptions<unknown>;\n}): Promise<AgentSnapshot> {\n const store = resolveSnapshotStore(params.durable);\n\n if (!store) {\n throw new AgentExecutionError(\n `agent \"${params.agentName}\" has no durable store configured — set \\`durable: { store }\\` on the config or call \\`ai.config({ defaultSnapshotStore })\\` at boot before calling resume()`,\n { context: { runId: params.runId } },\n );\n }\n\n const snapshot = (await store.load(params.runId)) ?? null;\n\n if (!snapshot) {\n throw new AgentExecutionError(\n `agent \"${params.agentName}\": no snapshot for runId \"${params.runId}\"`,\n { context: { runId: params.runId } },\n );\n }\n\n if (!params.options?.force && snapshot.signature !== params.signature) {\n throw new AgentDriftError(\n `agent \"${params.agentName}\" signature drift on resume`,\n {\n savedSignature: snapshot.signature,\n currentSignature: params.signature,\n runId: params.runId,\n },\n );\n }\n\n return snapshot;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAoCA,SAAS,qBACP,SAC0C;CAC1C,OACE,SAAS,SACR,4BAA4B;AAEjC;;;;;;;;;;AAgCA,eAAsB,qBACpB,QACyB;CACzB,MAAM,QAA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S,SAAS,cAAc,OAAO,WAC1D,MAAM,IAAI,gBACR,UAAU,OAAO,UAAU,8BAC3B;EACE,gBAAgB,SAAS;EACzB,kBAAkB,OAAO;EACzB,OAAO,OAAO;CAChB,CACF;CAGF,OAAO;AACT"}
@@ -0,0 +1,5 @@
1
+ import "../../index.mjs";
2
+ import "./utils/index.mjs";
3
+ import { log } from "@warlock.js/logger";
4
+
5
+ export { };
@@ -1,4 +1,7 @@
1
1
  import "./embedder.mjs";
2
+ import "./image.mjs";
3
+ import "./speech.mjs";
4
+ import "./transcription.mjs";
2
5
  import "./sdk.mjs";
3
6
 
4
7
  export { };
@@ -1,6 +1,9 @@
1
1
  import "../../index.mjs";
2
2
  import "./embedder.mjs";
3
+ import "./image.mjs";
3
4
  import "./model.mjs";
5
+ import "./speech.mjs";
6
+ import "./transcription.mjs";
4
7
  import "openai";
5
8
 
6
9
  export { };
@@ -0,0 +1,5 @@
1
+ import "../../index.mjs";
2
+ import "./utils/index.mjs";
3
+ import { log } from "@warlock.js/logger";
4
+
5
+ export { };
@@ -0,0 +1,6 @@
1
+ import "../../index.mjs";
2
+ import "./utils/index.mjs";
3
+ import { log } from "@warlock.js/logger";
4
+ import "openai";
5
+
6
+ export { };
@@ -1,3 +1,4 @@
1
+ import "./to-openai-messages.mjs";
1
2
  import "./to-openai-tools.mjs";
2
3
  import "./wrap-openai-error.mjs";
3
4
 
@@ -0,0 +1,3 @@
1
+ import "../../../index.mjs";
2
+
3
+ export { };
package/esm/ai.d.mts CHANGED
@@ -12,6 +12,10 @@ import { setAIConfig } from "./config.mjs";
12
12
  import { dataset } from "./eval/dataset.mjs";
13
13
  import { evalScorers } from "./eval/index.mjs";
14
14
  import { humanApproval } from "./human/human-approval.mjs";
15
+ import { image } from "./image/image.mjs";
16
+ import { speech } from "./speech/speech.mjs";
17
+ import { audioFromBuffer, audioFromFile, audioMediaTypeForFilename } from "./transcribe/audio-input.mjs";
18
+ import { transcribe } from "./transcribe/transcribe.mjs";
15
19
  import { resume } from "./human/resume.mjs";
16
20
  import { memory as memory$1 } from "./human/stores/memory.mjs";
17
21
  import { pg as pg$1 } from "./human/stores/pg.mjs";
@@ -28,8 +32,19 @@ import { orchestrator } from "./orchestrator/orchestrator.mjs";
28
32
  import { planner } from "./planner/planner.mjs";
29
33
  import { defaultPromptsManager } from "./prompts/prompts-manager.mjs";
30
34
  import { rag } from "./rag/rag.mjs";
35
+ import { chunk } from "./rag/chunk/chunk.mjs";
36
+ import { cacheVectorStore } from "./rag/store/cache-vector-store.mjs";
37
+ import { pgVectorStore, vectorLiteral } from "./rag/store/pg-vector-store.mjs";
38
+ import { loadText } from "./rag/loaders/load-text.mjs";
39
+ import { loadHtml } from "./rag/loaders/load-html.mjs";
40
+ import { loadWeb } from "./rag/loaders/load-web.mjs";
41
+ import { loadPdf } from "./rag/loaders/load-pdf.mjs";
31
42
  import { keywordReranker } from "./rag/rerank/keyword-reranker.mjs";
32
43
  import { llmReranker } from "./rag/rerank/llm-reranker.mjs";
44
+ import { reciprocalRankFusion } from "./rag/hybrid/rrf.mjs";
45
+ import { bm25Rank } from "./rag/hybrid/bm25.mjs";
46
+ import { hybridRank } from "./rag/hybrid/hybrid-rank.mjs";
47
+ import { multiQuery } from "./rag/transforms/multi-query.mjs";
33
48
  import { skills } from "./skills/skills.mjs";
34
49
  import { systemPrompt } from "./system-prompt/system-prompt.mjs";
35
50
  import { prompt } from "./prompt/prompt.mjs";
@@ -72,6 +87,18 @@ interface Ai {
72
87
  rag: typeof rag & {
73
88
  keywordReranker: typeof keywordReranker;
74
89
  llmReranker: typeof llmReranker;
90
+ chunk: typeof chunk;
91
+ cacheVectorStore: typeof cacheVectorStore;
92
+ pgVectorStore: typeof pgVectorStore;
93
+ vectorLiteral: typeof vectorLiteral;
94
+ loadText: typeof loadText;
95
+ loadHtml: typeof loadHtml;
96
+ loadWeb: typeof loadWeb;
97
+ loadPdf: typeof loadPdf;
98
+ bm25Rank: typeof bm25Rank;
99
+ reciprocalRankFusion: typeof reciprocalRankFusion;
100
+ hybridRank: typeof hybridRank;
101
+ multiQuery: typeof multiQuery;
75
102
  };
76
103
  spawnSubAgent: typeof spawnSubAgent;
77
104
  router: typeof router;
@@ -81,6 +108,24 @@ interface Ai {
81
108
  streamObject: typeof streamObject;
82
109
  /** Serve an executable as an SSE HTTP endpoint — production serving primitive (A3). */
83
110
  serve: typeof serve;
111
+ /**
112
+ * Generate images from a text prompt — the image-output verb of the
113
+ * output-modality track (Theme I). Wraps an `ImageModelContract` (from
114
+ * `openai.image(...)` / `google.image(...)`) in the uniform
115
+ * never-throws `{ data, error, usage, report }` envelope with cost-truth
116
+ * and observability.
117
+ */
118
+ image: typeof image;
119
+ /** Text-to-speech (TTS) — the audio-output verb of the modality track (Theme I). */
120
+ speech: typeof speech;
121
+ /** Speech-to-text (STT / transcription) — the audio-input verb of the modality track (Theme I). */
122
+ transcribe: typeof transcribe;
123
+ /** Read an audio file from disk → `AudioInput` for `ai.transcribe` (non-AI file plumbing). */
124
+ audioFromFile: typeof audioFromFile;
125
+ /** Package raw audio bytes → `AudioInput` for `ai.transcribe`. */
126
+ audioFromBuffer: typeof audioFromBuffer;
127
+ /** Resolve the audio media type from a filename's extension. */
128
+ audioMediaTypeForFilename: typeof audioMediaTypeForFilename;
84
129
  fallbackModel: typeof fallbackModel;
85
130
  eval: typeof evalScorers;
86
131
  dataset: typeof dataset;
package/esm/ai.d.mts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"ai.d.mts","names":[],"sources":["../../../../../../@warlock.js/ai/src/ai.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;UAuDiB,EAAA;EACf,MAAA,SAAe,WAAA;EACf,IAAA,SAAa,IAAA;EACb,KAAA,SAAc,KAAA;EACd,YAAA,SAAqB,YAAA;EACrB,OAAA,SAAgB,OAAA;EAChB,WAAA,SAAoB,WAAA;EACpB,QAAA,SAAiB,QAAA;EACjB,IAAA,SAA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;EAjCA;EAmCxB,yBAAA,SAAkC,yBAAA;EAClC,aAAA,SAAsB,aAAA;EACtB,IAAA,SAAa,WAAA;EACb,OAAA,SAAgB,OAAA;EAChB,MAAA,SAAe,MAAA;EAjCgB;;;;;;;EAyC/B,OAAA,EAAS,UAAA,QAAkB,qBAAA;EAC3B,GAAA,SAAY,GAAA;EACZ,UAAA,SAAmB,UAAA;EACnB,UAAA;IACE,MAAA,SAAe,MAAA;IACf,SAAA,SAAkB,WAAA;IAClB,aAAA,SAAsB,aAAA;IACtB,OAAA,SAAgB,iBAAA;IAChB,OAAA,SAAgB,OAAA;IAChB,wBAAA,SAAiC,wBAAA;EAAA;EAEnC,UAAA;IACE,MAAA,SAAe,MAAA;IACf,EAAA,SAAW,EAAA;IACX,KAAA,SAAc,KAAA;EAAA;EAEhB,QAAA;IACE,MAAA,SAAe,QAAA;IACf,EAAA,SAAW,IAAA;IACX,KAAA,SAAc,OAAA;EAAA;EAVmB;;;;;;;;EAoBnC,KAAA;IACE,QAAA,SAAiB,aAAA;IACjB,MAAA,SAAe,MAAA;IACf,SAAA;MACE,MAAA,SAAe,QAAA;MACf,EAAA,SAAW,IAAA;MACX,KAAA,SAAc,OAAA;IAAA;EAAA;EArGlB;;;;;EA6GA,SAAA,SAAkB,SAAA;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cA6CP,EAAA,EAwER,EAAE"}
package/esm/ai.mjs CHANGED
@@ -21,6 +21,13 @@ import { redis } from "./checkpoint/redis.mjs";
21
21
  import { dataset } from "./eval/dataset.mjs";
22
22
  import { evalScorers } from "./eval/index.mjs";
23
23
  import { human } from "./human/register.mjs";
24
+ import { image } from "./image/image.mjs";
25
+ import "./image/index.mjs";
26
+ import { speech } from "./speech/speech.mjs";
27
+ import "./speech/index.mjs";
28
+ import { audioFromBuffer, audioFromFile, audioMediaTypeForFilename } from "./transcribe/audio-input.mjs";
29
+ import { transcribe } from "./transcribe/transcribe.mjs";
30
+ import "./transcribe/index.mjs";
24
31
  import { guardrail as guardrail$1 } from "./guard/guardrail.mjs";
25
32
  import { mockRouter } from "./mock/mock-router.mjs";
26
33
  import "./mock/index.mjs";
@@ -35,9 +42,20 @@ import { instruction } from "./system-prompt/instruction.mjs";
35
42
  import { persona } from "./system-prompt/persona.mjs";
36
43
  import { systemPrompt } from "./system-prompt/system-prompt.mjs";
37
44
  import { defaultPromptsManager } from "./prompts/prompts-manager.mjs";
45
+ import { chunk } from "./rag/chunk/chunk.mjs";
46
+ import { cacheVectorStore } from "./rag/store/cache-vector-store.mjs";
38
47
  import { rag } from "./rag/rag.mjs";
48
+ import { pgVectorStore, vectorLiteral } from "./rag/store/pg-vector-store.mjs";
49
+ import { loadText } from "./rag/loaders/load-text.mjs";
50
+ import { loadHtml } from "./rag/loaders/load-html.mjs";
51
+ import { loadWeb } from "./rag/loaders/load-web.mjs";
52
+ import { loadPdf } from "./rag/loaders/load-pdf.mjs";
39
53
  import { keywordReranker } from "./rag/rerank/keyword-reranker.mjs";
40
54
  import { llmReranker } from "./rag/rerank/llm-reranker.mjs";
55
+ import { reciprocalRankFusion } from "./rag/hybrid/rrf.mjs";
56
+ import { bm25Rank } from "./rag/hybrid/bm25.mjs";
57
+ import { hybridRank } from "./rag/hybrid/hybrid-rank.mjs";
58
+ import { multiQuery } from "./rag/transforms/multi-query.mjs";
41
59
  import "./rag/index.mjs";
42
60
  import { prompt } from "./prompt/prompt.mjs";
43
61
  import "./prompt/index.mjs";
@@ -113,7 +131,19 @@ const ai = {
113
131
  planner,
114
132
  rag: Object.assign(rag, {
115
133
  keywordReranker,
116
- llmReranker
134
+ llmReranker,
135
+ chunk,
136
+ cacheVectorStore,
137
+ pgVectorStore,
138
+ vectorLiteral,
139
+ loadText,
140
+ loadHtml,
141
+ loadWeb,
142
+ loadPdf,
143
+ bm25Rank,
144
+ reciprocalRankFusion,
145
+ hybridRank,
146
+ multiQuery
117
147
  }),
118
148
  spawnSubAgent,
119
149
  router,
@@ -121,6 +151,12 @@ const ai = {
121
151
  batch,
122
152
  streamObject,
123
153
  serve,
154
+ image,
155
+ speech,
156
+ transcribe,
157
+ audioFromFile,
158
+ audioFromBuffer,
159
+ audioMediaTypeForFilename,
124
160
  fallbackModel,
125
161
  eval: evalScorers,
126
162
  dataset,
package/esm/ai.mjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"ai.mjs","names":["checkpointMemory","checkpointPg","checkpointRedis","snapshotMemory","snapshotPg","snapshotRedis","guardrailSuite"],"sources":["../../../../../../@warlock.js/ai/src/ai.ts"],"sourcesContent":["import { agent } from \"./agent/agent\";\nimport { batch } from \"./batch\";\nimport { streamObject } from \"./object-stream\";\nimport { serve } from \"./serve\";\nimport {\n checkpointMemory,\n checkpointPg,\n checkpointRedis,\n} from \"./checkpoint\";\nimport { setAIConfig } from \"./config\";\nimport { dataset, evalScorers } from \"./eval\";\nimport { humanApproval } from \"./human/human-approval\";\nimport { human } from \"./human/register\";\nimport { resume } from \"./human/resume\";\nimport {\n interruptMemory,\n interruptPg,\n interruptRedis,\n} from \"./human/stores\";\nimport { guardrail as guardrailSuite } from \"./guard/guardrail\";\nimport { budget, readBudgetFallbackSignal } from \"./middleware/builtins/budget\";\nimport { memory } from \"./memory\";\nimport { guardrail } from \"./middleware/builtins/guardrail\";\nimport { semanticCache } from \"./middleware/builtins/semantic-cache\";\nimport { composeMiddleware, forTool } from \"./middleware/helpers\";\nimport { mockRouter } from \"./mock\";\nimport { fallbackModel } from \"./model\";\nimport { orchestrator } from \"./orchestrator\";\nimport { planner } from \"./planner\";\nimport { defaultPromptsManager } from \"./prompts/prompts-manager\";\nimport { rag } from \"./rag\";\nimport { keywordReranker } from \"./rag/rerank/keyword-reranker\";\nimport { llmReranker } from \"./rag/rerank/llm-reranker\";\nimport { spawnSubAgent } from \"./agent/spawn-sub-agent\";\nimport { skills } from \"./skills\";\nimport { prompt } from \"./prompt\";\nimport { vcr } from \"./vcr\";\nimport { snapshotMemory, snapshotPg, snapshotRedis } from \"./snapshot\";\nimport { fanOut, router } from \"./supervisor\";\nimport { supervisor } from \"./supervisor/supervisor\";\nimport { team } from \"./team/team\";\nimport { instruction } from \"./system-prompt/instruction\";\nimport { persona } from \"./system-prompt/persona\";\nimport { systemPrompt } from \"./system-prompt/system-prompt\";\nimport { tool } from \"./tool/tool\";\nimport { step } from \"./workflow/step\";\nimport { workflow } from \"./workflow/workflow\";\n\n/**\n * The shape of the top-level `ai` namespace. Declared as an `interface` (not an\n * inferred `const` type) so satellite packages can attach their verb via\n * `declare module \"@warlock.js/ai\" { interface Ai { … } }` — e.g. `ai.workspace`,\n * `ai.tools`, `ai.mcp`, `ai.human`. The runtime object below is asserted to this\n * type; a satellite assigns its member on import.\n */\nexport interface Ai {\n config: typeof setAIConfig;\n tool: typeof tool;\n agent: typeof agent;\n systemPrompt: typeof systemPrompt;\n persona: typeof persona;\n instruction: typeof instruction;\n workflow: typeof workflow;\n step: typeof step;\n supervisor: typeof supervisor;\n team: typeof team;\n orchestrator: typeof orchestrator;\n memory: typeof memory;\n skills: typeof skills;\n planner: typeof planner;\n rag: typeof rag & {\n keywordReranker: typeof keywordReranker;\n llmReranker: typeof llmReranker;\n };\n spawnSubAgent: typeof spawnSubAgent;\n router: typeof router;\n fanOut: typeof fanOut;\n batch: typeof batch;\n /** Structured-output streaming — partial-object snapshots + a strict final parse (A1). */\n streamObject: typeof streamObject;\n /** Serve an executable as an SSE HTTP endpoint — production serving primitive (A3). */\n serve: typeof serve;\n fallbackModel: typeof fallbackModel;\n eval: typeof evalScorers;\n dataset: typeof dataset;\n prompt: typeof prompt;\n /**\n * Process-wide registry of named, versioned `systemPrompt(...)` builders,\n * keyed by `name@version`. A `systemPrompt(input, { name })` (or any\n * `.meta({ name })` rename) auto-registers here; `ai.prompts.get(name)` /\n * `.resolve(name)` reads them back, and `systemPrompt().merge(name)` folds a\n * registered prompt into a new one.\n */\n prompts: ReturnType<typeof defaultPromptsManager>;\n vcr: typeof vcr;\n mockRouter: typeof mockRouter;\n middleware: {\n budget: typeof budget;\n guardrail: typeof guardrail;\n semanticCache: typeof semanticCache;\n compose: typeof composeMiddleware;\n forTool: typeof forTool;\n readBudgetFallbackSignal: typeof readBudgetFallbackSignal;\n };\n checkpoint: {\n memory: typeof checkpointMemory;\n pg: typeof checkpointPg;\n redis: typeof checkpointRedis;\n };\n snapshot: {\n memory: typeof snapshotMemory;\n pg: typeof snapshotPg;\n redis: typeof snapshotRedis;\n };\n /**\n * Human-in-the-loop tool approval (interrupt / resume).\n *\n * - `human.approval(options)` — the `tool.before` approval-gate middleware.\n * - `human.resume(id, decision, options)` — out-of-process durable resume.\n * - `human.interrupt.{memory,pg,redis}()` — durable {@link InterruptStore}\n * factories (memory ships real; pg/redis are lazy optional peers).\n */\n human: {\n approval: typeof humanApproval;\n resume: typeof resume;\n interrupt: {\n memory: typeof interruptMemory;\n pg: typeof interruptPg;\n redis: typeof interruptRedis;\n };\n };\n /**\n * Content-intelligence guardrail. `ai.guardrail(options)` builds a composed\n * input / output / tool middleware; `ai.guardrail.{pii,topic,injection,moderation}`\n * are the built-in detector factories.\n */\n guardrail: typeof guardrailSuite;\n}\n\n/**\n * Top-level `ai` namespace — holds built-in factories and user-registered SDK adapters.\n *\n * Factories:\n * - `ai.tool(...)` — wrap an async function with a schema-validated input.\n * - `ai.agent(...)` — build an executable agent from model + tools + prompt.\n * - `ai.systemPrompt(...)` — compose a layered persona + instructions prompt.\n * - `ai.persona(text)` — reusable persona block (can be passed to `systemPrompt`).\n * - `ai.instruction(text)` — reusable instruction block (can be passed to `systemPrompt`).\n * - `ai.orchestrator(...)` — session-state manager wrapped around a supervisor (durable session, drift detection, resume, commands).\n * - `ai.memory(...)` — build an agent-memory store with WORKING (in-run scratch) and SEMANTIC (cache-driver `.similar()` recall) tiers.\n * - `ai.skills(...)` — build a runtime skills library (always-injected metadata catalog + on-demand loadSkill tool).\n * - `ai.planner(...)` — build an executable that generates an ordered plan over registered capabilities, then runs it step-by-step.\n * - `ai.spawnSubAgent(spec)` — thin wrapper that builds a fresh one-shot `agent()` with an optional per-task `budget` and runs the task once. A general primitive (not planner-specific).\n * - `ai.router(...)` — build a supervisor-compatible routing agent from named intents.\n * - `ai.fanOut(unit, count)` — spread one agent/workflow into N intent entries for voting / self-consistency.\n * - `ai.batch(executable, items, opts?)` — run any executable over a dataset with bounded concurrency + per-item retry.\n * - `ai.fallbackModel(models, opts?)` — wrap an ordered model list that fails over to the next on transient provider errors.\n * - `ai.eval.{exact,contains,predicate,judge}(...)` — built-in scorer factories for `agent.eval(...)`.\n * - `ai.mockRouter(decisions, opts?)` — deterministic supervisor `route` callback for tests.\n * - `ai.checkpoint.{memory,pg,redis}()` — durable orchestrator session checkpoint stores.\n * - `ai.snapshot.{memory,pg,redis}()` — supervisor-run snapshot stores for `iterate: true` resume.\n * - `ai.human.approval(...)` / `ai.human.resume(...)` / `ai.human.interrupt.{memory,pg,redis}()` — human-in-the-loop tool approval (interrupt / resume).\n * - `ai.guardrail(options)` + `ai.guardrail.{pii,topic,injection,moderation}(...)` — content-intelligence guardrails (moderation / PII / injection / topic).\n * - `ai.openai.model(...)` / `ai.anthropic.model(...)` / ... once the adapter SDK is registered.\n *\n * @example\n * const alex = ai.persona(\"You are Alex, a TypeScript expert.\");\n * const replyIn = ai.instruction(\"Respond in {{language|English}}.\");\n *\n * const prompt = ai.systemPrompt().persona(alex).instruction(replyIn);\n *\n * const myAgent = ai.agent({\n * model: ai.openai.model({ name: \"gpt-4o\" }),\n * systemPrompt: prompt,\n * tools: [myTool],\n * });\n *\n * const result = await myAgent.execute(\"What is the weather in Cairo?\", {\n * placeholders: { language: \"Arabic\" },\n * });\n */\nexport const ai = {\n config: setAIConfig,\n tool,\n agent,\n systemPrompt,\n persona,\n instruction,\n workflow,\n step,\n supervisor,\n team,\n orchestrator,\n memory,\n skills,\n planner,\n rag: Object.assign(rag, { keywordReranker, llmReranker }),\n spawnSubAgent,\n router,\n fanOut,\n batch,\n streamObject,\n serve,\n fallbackModel,\n eval: evalScorers,\n dataset,\n prompt,\n prompts: defaultPromptsManager(),\n vcr,\n mockRouter,\n middleware: {\n budget,\n guardrail,\n semanticCache,\n compose: composeMiddleware,\n forTool,\n readBudgetFallbackSignal,\n },\n checkpoint: {\n memory: checkpointMemory,\n pg: checkpointPg,\n redis: checkpointRedis,\n },\n snapshot: {\n memory: snapshotMemory,\n pg: snapshotPg,\n redis: snapshotRedis,\n },\n human,\n guardrail: guardrailSuite,\n // Asserted (not `: Ai`) so a consumer build that augments `Ai` with a\n // satellite verb (e.g. `workspace`) doesn't flag this literal as missing it.\n} as Ai;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqLA,MAAa,KAAK;CAChB,QAAQ;CACR;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA,KAAK,OAAO,OAAO,KAAK;EAAE;EAAiB;CAAY,CAAC;CACxD;CACA;CACA;CACA;CACA;CACA;CACA;CACA,MAAM;CACN;CACA;CACA,SAAS,sBAAsB;CAC/B;CACA;CACA,YAAY;EACV;EACA;EACA;EACA,SAAS;EACT;EACA;CACF;CACA,YAAY;EACV,QAAQA;EACJC;EACGC;CACT;CACA,UAAU;EACR,QAAQC;EACR,IAAIC;EACJ,OAAOC;CACT;CACA;CACA,WAAWC;AAGb"}
1
+ {"version":3,"file":"ai.mjs","names":["checkpointMemory","checkpointPg","checkpointRedis","snapshotMemory","snapshotPg","snapshotRedis","guardrailSuite"],"sources":["../../../../../../@warlock.js/ai/src/ai.ts"],"sourcesContent":["import { agent } from \"./agent/agent\";\nimport { batch } from \"./batch\";\nimport { streamObject } from \"./object-stream\";\nimport { serve } from \"./serve\";\nimport {\n checkpointMemory,\n checkpointPg,\n checkpointRedis,\n} from \"./checkpoint\";\nimport { setAIConfig } from \"./config\";\nimport { dataset, evalScorers } from \"./eval\";\nimport { humanApproval } from \"./human/human-approval\";\nimport { human } from \"./human/register\";\nimport { image } from \"./image\";\nimport { speech } from \"./speech\";\nimport {\n audioFromBuffer,\n audioFromFile,\n audioMediaTypeForFilename,\n transcribe,\n} from \"./transcribe\";\nimport { resume } from \"./human/resume\";\nimport {\n interruptMemory,\n interruptPg,\n interruptRedis,\n} from \"./human/stores\";\nimport { guardrail as guardrailSuite } from \"./guard/guardrail\";\nimport { budget, readBudgetFallbackSignal } from \"./middleware/builtins/budget\";\nimport { memory } from \"./memory\";\nimport { guardrail } from \"./middleware/builtins/guardrail\";\nimport { semanticCache } from \"./middleware/builtins/semantic-cache\";\nimport { composeMiddleware, forTool } from \"./middleware/helpers\";\nimport { mockRouter } from \"./mock\";\nimport { fallbackModel } from \"./model\";\nimport { orchestrator } from \"./orchestrator\";\nimport { planner } from \"./planner\";\nimport { defaultPromptsManager } from \"./prompts/prompts-manager\";\nimport {\n bm25Rank,\n cacheVectorStore,\n chunk,\n hybridRank,\n keywordReranker,\n llmReranker,\n loadHtml,\n loadPdf,\n loadText,\n loadWeb,\n multiQuery,\n pgVectorStore,\n rag,\n reciprocalRankFusion,\n vectorLiteral,\n} from \"./rag\";\nimport { spawnSubAgent } from \"./agent/spawn-sub-agent\";\nimport { skills } from \"./skills\";\nimport { prompt } from \"./prompt\";\nimport { vcr } from \"./vcr\";\nimport { snapshotMemory, snapshotPg, snapshotRedis } from \"./snapshot\";\nimport { fanOut, router } from \"./supervisor\";\nimport { supervisor } from \"./supervisor/supervisor\";\nimport { team } from \"./team/team\";\nimport { instruction } from \"./system-prompt/instruction\";\nimport { persona } from \"./system-prompt/persona\";\nimport { systemPrompt } from \"./system-prompt/system-prompt\";\nimport { tool } from \"./tool/tool\";\nimport { step } from \"./workflow/step\";\nimport { workflow } from \"./workflow/workflow\";\n\n/**\n * The shape of the top-level `ai` namespace. Declared as an `interface` (not an\n * inferred `const` type) so satellite packages can attach their verb via\n * `declare module \"@warlock.js/ai\" { interface Ai { … } }` — e.g. `ai.workspace`,\n * `ai.tools`, `ai.mcp`, `ai.human`. The runtime object below is asserted to this\n * type; a satellite assigns its member on import.\n */\nexport interface Ai {\n config: typeof setAIConfig;\n tool: typeof tool;\n agent: typeof agent;\n systemPrompt: typeof systemPrompt;\n persona: typeof persona;\n instruction: typeof instruction;\n workflow: typeof workflow;\n step: typeof step;\n supervisor: typeof supervisor;\n team: typeof team;\n orchestrator: typeof orchestrator;\n memory: typeof memory;\n skills: typeof skills;\n planner: typeof planner;\n rag: typeof rag & {\n keywordReranker: typeof keywordReranker;\n llmReranker: typeof llmReranker;\n chunk: typeof chunk;\n cacheVectorStore: typeof cacheVectorStore;\n pgVectorStore: typeof pgVectorStore;\n vectorLiteral: typeof vectorLiteral;\n loadText: typeof loadText;\n loadHtml: typeof loadHtml;\n loadWeb: typeof loadWeb;\n loadPdf: typeof loadPdf;\n bm25Rank: typeof bm25Rank;\n reciprocalRankFusion: typeof reciprocalRankFusion;\n hybridRank: typeof hybridRank;\n multiQuery: typeof multiQuery;\n };\n spawnSubAgent: typeof spawnSubAgent;\n router: typeof router;\n fanOut: typeof fanOut;\n batch: typeof batch;\n /** Structured-output streaming — partial-object snapshots + a strict final parse (A1). */\n streamObject: typeof streamObject;\n /** Serve an executable as an SSE HTTP endpoint — production serving primitive (A3). */\n serve: typeof serve;\n /**\n * Generate images from a text prompt — the image-output verb of the\n * output-modality track (Theme I). Wraps an `ImageModelContract` (from\n * `openai.image(...)` / `google.image(...)`) in the uniform\n * never-throws `{ data, error, usage, report }` envelope with cost-truth\n * and observability.\n */\n image: typeof image;\n /** Text-to-speech (TTS) — the audio-output verb of the modality track (Theme I). */\n speech: typeof speech;\n /** Speech-to-text (STT / transcription) — the audio-input verb of the modality track (Theme I). */\n transcribe: typeof transcribe;\n /** Read an audio file from disk → `AudioInput` for `ai.transcribe` (non-AI file plumbing). */\n audioFromFile: typeof audioFromFile;\n /** Package raw audio bytes → `AudioInput` for `ai.transcribe`. */\n audioFromBuffer: typeof audioFromBuffer;\n /** Resolve the audio media type from a filename's extension. */\n audioMediaTypeForFilename: typeof audioMediaTypeForFilename;\n fallbackModel: typeof fallbackModel;\n eval: typeof evalScorers;\n dataset: typeof dataset;\n prompt: typeof prompt;\n /**\n * Process-wide registry of named, versioned `systemPrompt(...)` builders,\n * keyed by `name@version`. A `systemPrompt(input, { name })` (or any\n * `.meta({ name })` rename) auto-registers here; `ai.prompts.get(name)` /\n * `.resolve(name)` reads them back, and `systemPrompt().merge(name)` folds a\n * registered prompt into a new one.\n */\n prompts: ReturnType<typeof defaultPromptsManager>;\n vcr: typeof vcr;\n mockRouter: typeof mockRouter;\n middleware: {\n budget: typeof budget;\n guardrail: typeof guardrail;\n semanticCache: typeof semanticCache;\n compose: typeof composeMiddleware;\n forTool: typeof forTool;\n readBudgetFallbackSignal: typeof readBudgetFallbackSignal;\n };\n checkpoint: {\n memory: typeof checkpointMemory;\n pg: typeof checkpointPg;\n redis: typeof checkpointRedis;\n };\n snapshot: {\n memory: typeof snapshotMemory;\n pg: typeof snapshotPg;\n redis: typeof snapshotRedis;\n };\n /**\n * Human-in-the-loop tool approval (interrupt / resume).\n *\n * - `human.approval(options)` — the `tool.before` approval-gate middleware.\n * - `human.resume(id, decision, options)` — out-of-process durable resume.\n * - `human.interrupt.{memory,pg,redis}()` — durable {@link InterruptStore}\n * factories (memory ships real; pg/redis are lazy optional peers).\n */\n human: {\n approval: typeof humanApproval;\n resume: typeof resume;\n interrupt: {\n memory: typeof interruptMemory;\n pg: typeof interruptPg;\n redis: typeof interruptRedis;\n };\n };\n /**\n * Content-intelligence guardrail. `ai.guardrail(options)` builds a composed\n * input / output / tool middleware; `ai.guardrail.{pii,topic,injection,moderation}`\n * are the built-in detector factories.\n */\n guardrail: typeof guardrailSuite;\n}\n\n/**\n * Top-level `ai` namespace — holds built-in factories and user-registered SDK adapters.\n *\n * Factories:\n * - `ai.tool(...)` — wrap an async function with a schema-validated input.\n * - `ai.agent(...)` — build an executable agent from model + tools + prompt.\n * - `ai.systemPrompt(...)` — compose a layered persona + instructions prompt.\n * - `ai.persona(text)` — reusable persona block (can be passed to `systemPrompt`).\n * - `ai.instruction(text)` — reusable instruction block (can be passed to `systemPrompt`).\n * - `ai.orchestrator(...)` — session-state manager wrapped around a supervisor (durable session, drift detection, resume, commands).\n * - `ai.memory(...)` — build an agent-memory store with WORKING (in-run scratch) and SEMANTIC (cache-driver `.similar()` recall) tiers.\n * - `ai.skills(...)` — build a runtime skills library (always-injected metadata catalog + on-demand loadSkill tool).\n * - `ai.planner(...)` — build an executable that generates an ordered plan over registered capabilities, then runs it step-by-step.\n * - `ai.spawnSubAgent(spec)` — thin wrapper that builds a fresh one-shot `agent()` with an optional per-task `budget` and runs the task once. A general primitive (not planner-specific).\n * - `ai.router(...)` — build a supervisor-compatible routing agent from named intents.\n * - `ai.fanOut(unit, count)` — spread one agent/workflow into N intent entries for voting / self-consistency.\n * - `ai.batch(executable, items, opts?)` — run any executable over a dataset with bounded concurrency + per-item retry.\n * - `ai.fallbackModel(models, opts?)` — wrap an ordered model list that fails over to the next on transient provider errors.\n * - `ai.eval.{exact,contains,predicate,judge}(...)` — built-in scorer factories for `agent.eval(...)`.\n * - `ai.mockRouter(decisions, opts?)` — deterministic supervisor `route` callback for tests.\n * - `ai.checkpoint.{memory,pg,redis}()` — durable orchestrator session checkpoint stores.\n * - `ai.snapshot.{memory,pg,redis}()` — supervisor-run snapshot stores for `iterate: true` resume.\n * - `ai.human.approval(...)` / `ai.human.resume(...)` / `ai.human.interrupt.{memory,pg,redis}()` — human-in-the-loop tool approval (interrupt / resume).\n * - `ai.guardrail(options)` + `ai.guardrail.{pii,topic,injection,moderation}(...)` — content-intelligence guardrails (moderation / PII / injection / topic).\n * - `ai.openai.model(...)` / `ai.anthropic.model(...)` / ... once the adapter SDK is registered.\n *\n * @example\n * const alex = ai.persona(\"You are Alex, a TypeScript expert.\");\n * const replyIn = ai.instruction(\"Respond in {{language|English}}.\");\n *\n * const prompt = ai.systemPrompt().persona(alex).instruction(replyIn);\n *\n * const myAgent = ai.agent({\n * model: ai.openai.model({ name: \"gpt-4o\" }),\n * systemPrompt: prompt,\n * tools: [myTool],\n * });\n *\n * const result = await myAgent.execute(\"What is the weather in Cairo?\", {\n * placeholders: { language: \"Arabic\" },\n * });\n */\nexport const ai = {\n config: setAIConfig,\n tool,\n agent,\n systemPrompt,\n persona,\n instruction,\n workflow,\n step,\n supervisor,\n team,\n orchestrator,\n memory,\n skills,\n planner,\n rag: Object.assign(rag, {\n keywordReranker,\n llmReranker,\n chunk,\n cacheVectorStore,\n pgVectorStore,\n vectorLiteral,\n loadText,\n loadHtml,\n loadWeb,\n loadPdf,\n bm25Rank,\n reciprocalRankFusion,\n hybridRank,\n multiQuery,\n }),\n spawnSubAgent,\n router,\n fanOut,\n batch,\n streamObject,\n serve,\n image,\n speech,\n transcribe,\n audioFromFile,\n audioFromBuffer,\n audioMediaTypeForFilename,\n fallbackModel,\n eval: evalScorers,\n dataset,\n prompt,\n prompts: defaultPromptsManager(),\n vcr,\n mockRouter,\n middleware: {\n budget,\n guardrail,\n semanticCache,\n compose: composeMiddleware,\n forTool,\n readBudgetFallbackSignal,\n },\n checkpoint: {\n memory: checkpointMemory,\n pg: checkpointPg,\n redis: checkpointRedis,\n },\n snapshot: {\n memory: snapshotMemory,\n pg: snapshotPg,\n redis: snapshotRedis,\n },\n human,\n guardrail: guardrailSuite,\n // Asserted (not `: Ai`) so a consumer build that augments `Ai` with a\n // satellite verb (e.g. `workspace`) doesn't flag this literal as missing it.\n} as Ai;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyOA,MAAa,KAAK;CAChB,QAAQ;CACR;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA,KAAK,OAAO,OAAO,KAAK;EACtB;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF,CAAC;CACD;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA,MAAM;CACN;CACA;CACA,SAAS,sBAAsB;CAC/B;CACA;CACA,YAAY;EACV;EACA;EACA;EACA,SAAS;EACT;EACA;CACF;CACA,YAAY;EACV,QAAQA;EACJC;EACGC;CACT;CACA,UAAU;EACR,QAAQC;EACR,IAAIC;EACJ,OAAOC;CACT;CACA;CACA,WAAWC;AAGb"}
@@ -25,7 +25,15 @@ import { StandardSchemaV1 } from "@standard-schema/spec";
25
25
  * });
26
26
  */
27
27
  type AgentExecuteOptions<TOutput = unknown> = {
28
- /** Prior conversation messages to prepend as context */history?: Message[]; /** Files or URLs to attach to the message */
28
+ /**
29
+ * Caller-chosen stable run identifier. Auto-generated (`agent_<rand>`)
30
+ * when omitted. Load-bearing for durable resume: when `durable` is on,
31
+ * pass a stable `runId` here (or read the generated one off
32
+ * `result.report.runId`) so a later `agent.resume(runId)` can find the
33
+ * snapshot. Mirrors `SupervisorExecuteOptions.runId`.
34
+ */
35
+ runId?: string; /** Prior conversation messages to prepend as context */
36
+ history?: Message[]; /** Files or URLs to attach to the message */
29
37
  attachments?: Attachment[];
30
38
  /**
31
39
  * Trust-boundary policy for {@link attachments} (S1) — overrides
@@ -135,6 +143,18 @@ type AgentExecuteOptions<TOutput = unknown> = {
135
143
  */
136
144
  sessionId?: string;
137
145
  };
146
+ /**
147
+ * Options accepted by `agent.resume(runId, options?)`.
148
+ *
149
+ * `force: true` bypasses the signature drift check — use only when you
150
+ * have verified the definition change is safe for the in-flight
151
+ * snapshot. `AgentDriftError` is otherwise thrown without executing
152
+ * anything. Everything else mirrors {@link AgentExecuteOptions} (e.g.
153
+ * re-supply a `signal` to keep the resumed run cancellable).
154
+ */
155
+ type AgentResumeOptions<TOutput = unknown> = AgentExecuteOptions<TOutput> & {
156
+ /** Bypass the drift check and resume against the changed definition. */force?: boolean;
157
+ };
138
158
  //#endregion
139
- export { AgentExecuteOptions };
159
+ export { AgentExecuteOptions, AgentResumeOptions };
140
160
  //# sourceMappingURL=agent-options.type.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"agent-options.type.d.mts","names":[],"sources":["../../../../../../../../@warlock.js/ai/src/contracts/agent/agent-options.type.ts"],"mappings":";;;;;;;;;;;;;AAyBA;;;;;;;;;;;;;KAAY,mBAAA;EAmF4C,wDAjFtD,OAAA,GAAU,OAAA,IA8FA;EA5FV,WAAA,GAAc,UAAA;EAoG+B;;;;;;EA7F7C,gBAAA,GAAmB,gBAAA,EAAnB;EAEA,YAAA,GAAe,YAAA;EAAf;;;;EAKA,MAAA,GAAS,gBAAA,CAAiB,OAAA;EAyB1B;;;;;;;;;;;;;;;;;;;;;AA0ES;;;EA1ET,cAAA,GAAiB,MAAA;;;;;;;;;;;;;;;;;;;;;EAqBjB,MAAA;8EAEE,WAAA;EAAA;EAGF,YAAA,GAAe,oBAAA;;;;;;;;;;;EAWf,MAAA,GAAS,WAAA;EAET,EAAA,GAAK,OAAA,eACS,aAAA,IAAiB,OAAA,EAAS,aAAA,CAAc,CAAA;;;;;;;;;;;;EAatD,OAAA,GAAU,WAAA;;;;;;;;EAQV,kBAAA,GAAqB,wBAAA;;;;;;;;;;;;;EAarB,SAAA;AAAA"}
1
+ {"version":3,"file":"agent-options.type.d.mts","names":[],"sources":["../../../../../../../../@warlock.js/ai/src/contracts/agent/agent-options.type.ts"],"mappings":";;;;;;;;;;;;;AAyBA;;;;;;;;;;;;;KAAY,mBAAA;EA2F4C;;;;;;;EAnFtD,KAAA,WAEA;EAAA,OAAA,GAAU,OAAA,IAEV;EAAA,WAAA,GAAc,UAAA;EAOd;;;;;;EAAA,gBAAA,GAAmB,gBAAA,EAgCnB;EA9BA,YAAA,GAAe,YAAA;EAmDf;;;;EA9CA,MAAA,GAAS,gBAAA,CAAiB,OAAA;EA8DjB;;;;;;;;;;;;;;AAqCA;AAYX;;;;;;;;;EAtFE,cAAA,GAAiB,MAAA;;;;;;;;;;;;;;;;;;;;;EAqBjB,MAAA;8EAEE,WAAA;EAAA;EAGF,YAAA,GAAe,oBAAA;;;;;;;;;;;EAWf,MAAA,GAAS,WAAA;EAET,EAAA,GAAK,OAAA,eACS,aAAA,IAAiB,OAAA,EAAS,aAAA,CAAc,CAAA;;;;;;;;;;;;EAatD,OAAA,GAAU,WAAA;;;;;;;;EAQV,kBAAA,GAAqB,wBAAA;;;;;;;;;;;;;EAarB,SAAA;AAAA;;;;;;;;;;KAYU,kBAAA,sBAAwC,mBAAmB,CAAC,OAAA;0EAEtE,KAAA;AAAA"}
@@ -0,0 +1,90 @@
1
+ import { Message } from "../conversation-message.type.mjs";
2
+ import { Usage } from "../result/usage.type.mjs";
3
+ import { ToolCall } from "../result/tool-call.type.mjs";
4
+ import { LLMTrip } from "../result/llm-trip.type.mjs";
5
+
6
+ //#region ../@warlock.js/ai/src/contracts/agent/agent-snapshot.type.d.ts
7
+ /**
8
+ * Lifecycle status of a durable agent run, recorded on the persisted
9
+ * snapshot so `resume()` can decide whether a run is still in flight.
10
+ *
11
+ * - `"running"` — the trip loop is active; a resume is legitimate if
12
+ * the process crashed between trip boundaries.
13
+ * - `"completed"` — the agent terminated successfully; resume is a
14
+ * no-op and re-returns the final result rebuilt from the snapshot.
15
+ * - `"cancelled"` — aborted via `AbortSignal`; resume is allowed (the
16
+ * caller decides whether to retry).
17
+ * - `"failed"` — terminated with an error; resume after the fix.
18
+ */
19
+ type AgentSnapshotStatus = "running" | "completed" | "cancelled" | "failed";
20
+ /**
21
+ * Persisted shape written to the configured {@link
22
+ * import("../orchestrator/snapshot-store.contract").SnapshotStore} after
23
+ * every trip settles. Exists so `agent.resume(runId)` can re-hydrate the
24
+ * assembled conversation + completed trips + tool calls + running usage
25
+ * and continue the trip loop from the next `tripIndex`.
26
+ *
27
+ * **Checkpoint granularity is per-trip.** The snapshot is written at the
28
+ * end of `runTrip`, after every tool the trip requested has been
29
+ * dispatched and its result message appended — the only point in the
30
+ * loop where `messages`, `trips`, `toolCalls`, and `usage` are mutually
31
+ * consistent. A crash mid-trip loses only that in-flight trip (never
32
+ * checkpointed), which the resumed run re-issues cleanly.
33
+ *
34
+ * `signature` is a structural fingerprint covering model + provider +
35
+ * sorted tool names + maxTrips + output presence + version (see
36
+ * {@link import("../../agent/signature").computeAgentSignature}).
37
+ * `resume()` compares it against the current agent's signature; a
38
+ * mismatch throws `AgentDriftError` (bypassable with `{ force: true }`).
39
+ *
40
+ * Every field is JSON-serializable — `Message`, `LLMTrip`, `ToolCall`,
41
+ * and `Usage` are the same plain-data shapes already persisted on
42
+ * reports, so the snapshot round-trips through any `SnapshotStore`
43
+ * backend (`memory`, `pg`, `redis`) verbatim.
44
+ *
45
+ * @example
46
+ * const snapshot: AgentSnapshot | undefined = await store.load(runId);
47
+ * if (snapshot?.status === "running") {
48
+ * await agent.resume(runId);
49
+ * }
50
+ */
51
+ type AgentSnapshot = {
52
+ /** The store key — stable across the whole run. */runId: string; /** Resolved agent name, for the resume error message + attribution. */
53
+ agentName: string; /** Structural drift fingerprint (see `computeAgentSignature`). */
54
+ signature: string; /** `AgentConfig.version` — metadata only, never compared. */
55
+ version?: string; /** The original `execute(input)` value — needed to rebuild context. */
56
+ input: string;
57
+ /**
58
+ * The resolved system-prompt text captured once on the first run, so
59
+ * a resume skips `buildInitialMessages` (the messages array already
60
+ * holds the system turn). Absent when the agent had no prompt.
61
+ */
62
+ systemPrompt?: string;
63
+ /**
64
+ * The wire-level JSON Schema sent to the model for structured output,
65
+ * captured so resume re-issues continuation trips with the identical
66
+ * response contract. Absent when the agent produced untyped output.
67
+ */
68
+ responseSchema?: Record<string, unknown>; /** Registry name of the resolved named prompt, when one was used. */
69
+ promptName?: string; /** Registry version label paired with {@link AgentSnapshot.promptName}. */
70
+ promptVersion?: string;
71
+ /**
72
+ * The live conversation array — assistant turns (with `toolCalls`)
73
+ * plus tool-result turns — assembled across the persisted trips.
74
+ * Re-hydrated verbatim so the next trip sees the full history.
75
+ */
76
+ messages: Message[];
77
+ /**
78
+ * Every settled trip so far. `trips.length` is the next `tripIndex`
79
+ * the resumed loop starts at, so completed trips never re-run.
80
+ */
81
+ trips: LLMTrip[]; /** Every settled tool dispatch (flat, each carrying its `tripIndex`). */
82
+ toolCalls: ToolCall[]; /** Running usage total across the persisted trips — never double-counted. */
83
+ usage: Usage;
84
+ status: AgentSnapshotStatus;
85
+ startedAt: string;
86
+ savedAt: string;
87
+ };
88
+ //#endregion
89
+ export { AgentSnapshot, AgentSnapshotStatus };
90
+ //# sourceMappingURL=agent-snapshot.type.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-snapshot.type.d.mts","names":[],"sources":["../../../../../../../../@warlock.js/ai/src/contracts/agent/agent-snapshot.type.ts"],"mappings":";;;;;;;;AAiBA;;;;AAA+B;AAqC/B;;;;;KArCY,mBAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiFH;;;KA5CG,aAAA;qDAEV,KAAA;EAEA,SAAA;EAEA,SAAA;EAEA,OAAA;EAEA,KAAA;;;;;;EAMA,YAAA;;;;;;EAMA,cAAA,GAAiB,MAAA;EAEjB,UAAA;EAEA,aAAA;;;;;;EAMA,QAAA,EAAU,OAAA;;;;;EAKV,KAAA,EAAO,OAAA;EAEP,SAAA,EAAW,QAAA;EAEX,KAAA,EAAO,KAAA;EACP,MAAA,EAAQ,mBAAA;EACR,SAAA;EACA,OAAA;AAAA"}
@@ -3,7 +3,7 @@ import { ExecutableContract } from "../executable.contract.mjs";
3
3
  import { StreamContract } from "../stream/stream.contract.mjs";
4
4
  import { EvalOptions, EvalReport } from "./eval.type.mjs";
5
5
  import { AgentEventMap } from "../events/event-map.type.mjs";
6
- import { AgentExecuteOptions } from "./agent-options.type.mjs";
6
+ import { AgentExecuteOptions, AgentResumeOptions } from "./agent-options.type.mjs";
7
7
 
8
8
  //#region ../@warlock.js/ai/src/contracts/agent/agent.contract.d.ts
9
9
  /**
@@ -71,11 +71,39 @@ interface AgentContract<TOutput = unknown> extends ExecutableContract<string, Ag
71
71
  * `AgentConfig.description` at factory time.
72
72
  */
73
73
  readonly description?: string;
74
+ /**
75
+ * Structural drift fingerprint of the agent definition — model +
76
+ * provider + sorted tool names + maxTrips + output presence + version.
77
+ * Stamped on every durable snapshot and compared on `resume()`; a
78
+ * mismatch throws `AgentDriftError`. Always populated (computed at
79
+ * factory time), independent of whether `durable` is configured.
80
+ */
81
+ readonly signature: string;
74
82
  /**
75
83
  * Stream execution events in real time.
76
84
  * Yields typed StreamEvent values and resolves result when done.
77
85
  */
78
86
  stream(input: string, options?: AgentExecuteOptions<TOutput>): StreamContract<AgentResult<TOutput>>;
87
+ /**
88
+ * Resume a durable run after a crash. Loads the snapshot persisted
89
+ * under `runId` (requires `durable` on the config, or a global
90
+ * `defaultSnapshotStore`), re-hydrates the completed trips + tool
91
+ * calls + usage, and continues the trip loop from the next trip —
92
+ * never re-issuing a completed trip's model call or re-invoking its
93
+ * tools. A resume of an already-settled run re-returns the stored
94
+ * result without running anything.
95
+ *
96
+ * Refuses to continue when the current definition has structurally
97
+ * drifted from the snapshot (`AgentDriftError`), unless
98
+ * `{ force: true }` is passed. Throws `AgentExecutionError` when no
99
+ * store is configured or no snapshot exists for `runId`.
100
+ *
101
+ * @example
102
+ * const result = await writer.execute("research X", { runId: "run-42" });
103
+ * // ...process crashes mid-run...
104
+ * const recovered = await writer.resume("run-42");
105
+ */
106
+ resume(runId: string, options?: AgentResumeOptions<TOutput>): Promise<AgentResult<TOutput>>;
79
107
  /**
80
108
  * Subscribe a handler to a single event name for the lifetime of
81
109
  * this agent instance. Returns an unsubscribe function; calling it
@@ -1 +1 @@
1
- {"version":3,"file":"agent.contract.d.mts","names":[],"sources":["../../../../../../../../@warlock.js/ai/src/contracts/agent/agent.contract.ts"],"mappings":";;;;;;;;;;AAWA;;KAAY,iBAAA,iBAAkC,aAAA,KAC5C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A,CAAoB,OAAA,IAC7B,cAAA,CAAe,WAAA,CAAY,OAAA;EA+B3B;;;;;;;;;;;;;;;;;;;EAVH,MAAA,CACE,KAAA,UACA,OAAA,GAAU,kBAAA,CAAmB,OAAA,IAC5B,OAAA,CAAQ,WAAA,CAAY,OAAA;EA8DD;;;;;EAvDtB,EAAA,iBAAmB,aAAA,EACjB,KAAA,EAAO,CAAA,EACP,OAAA,EAAS,iBAAA,CAAkB,CAAA;;;;;EAO7B,GAAA,iBAAoB,aAAA,EAClB,KAAA,EAAO,CAAA,EACP,OAAA,EAAS,iBAAA,CAAkB,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA4C7B,IAAA,SAAa,OAAA,EAAS,OAAA,EAAS,WAAA,CAAY,KAAA,IAAS,OAAA,CAAQ,UAAA,CAAW,KAAA;AAAA"}
@@ -1,3 +1,4 @@
1
1
  import { EvalCase, EvalCaseResult, EvalJudge, EvalOptions, EvalReport, EvalScore, EvalScorer, EvalScorerContext } from "./eval.type.mjs";
2
2
  import { AgentContract, AgentEventHandler } from "./agent.contract.mjs";
3
- import { AgentExecuteOptions } from "./agent-options.type.mjs";
3
+ import { AgentExecuteOptions, AgentResumeOptions } from "./agent-options.type.mjs";
4
+ import { AgentSnapshot, AgentSnapshotStatus } from "./agent-snapshot.type.mjs";