@cogenta/agents 0.2.1 → 0.4.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 (229) hide show
  1. package/dist/agents/builtins.d.ts +51 -0
  2. package/dist/agents/builtins.d.ts.map +1 -0
  3. package/dist/agents/builtins.js +190 -0
  4. package/dist/agents/builtins.js.map +1 -0
  5. package/dist/agents/orchestrator.d.ts +95 -0
  6. package/dist/agents/orchestrator.d.ts.map +1 -0
  7. package/dist/agents/orchestrator.js +285 -0
  8. package/dist/agents/orchestrator.js.map +1 -0
  9. package/dist/agents/store.d.ts +71 -0
  10. package/dist/agents/store.d.ts.map +1 -0
  11. package/dist/agents/store.js +211 -0
  12. package/dist/agents/store.js.map +1 -0
  13. package/dist/agents/types.d.ts +10 -0
  14. package/dist/agents/types.d.ts.map +1 -1
  15. package/dist/assist/agent-identity.d.ts +44 -0
  16. package/dist/assist/agent-identity.d.ts.map +1 -0
  17. package/dist/assist/agent-identity.js +136 -0
  18. package/dist/assist/agent-identity.js.map +1 -0
  19. package/dist/assist/chat.d.ts +2 -0
  20. package/dist/assist/chat.d.ts.map +1 -1
  21. package/dist/assist/chat.js +14 -5
  22. package/dist/assist/chat.js.map +1 -1
  23. package/dist/assist/classify.d.ts +3 -2
  24. package/dist/assist/classify.d.ts.map +1 -1
  25. package/dist/assist/classify.js +30 -11
  26. package/dist/assist/classify.js.map +1 -1
  27. package/dist/assist/faq.d.ts +3 -2
  28. package/dist/assist/faq.d.ts.map +1 -1
  29. package/dist/assist/faq.js +31 -13
  30. package/dist/assist/faq.js.map +1 -1
  31. package/dist/assist/runtime.d.ts +8 -2
  32. package/dist/assist/runtime.d.ts.map +1 -1
  33. package/dist/assist/runtime.js +2 -2
  34. package/dist/assist/runtime.js.map +1 -1
  35. package/dist/assist/toolset.d.ts +10 -0
  36. package/dist/assist/toolset.d.ts.map +1 -1
  37. package/dist/assist/toolset.js +36 -8
  38. package/dist/assist/toolset.js.map +1 -1
  39. package/dist/assist/usage.d.ts +58 -0
  40. package/dist/assist/usage.d.ts.map +1 -0
  41. package/dist/assist/usage.js +53 -0
  42. package/dist/assist/usage.js.map +1 -0
  43. package/dist/assist/writing.d.ts +10 -9
  44. package/dist/assist/writing.d.ts.map +1 -1
  45. package/dist/assist/writing.js +126 -58
  46. package/dist/assist/writing.js.map +1 -1
  47. package/dist/audit/with-audit.d.ts +13 -0
  48. package/dist/audit/with-audit.d.ts.map +1 -1
  49. package/dist/audit/with-audit.js +6 -0
  50. package/dist/audit/with-audit.js.map +1 -1
  51. package/dist/autonomy/levels.d.ts +37 -0
  52. package/dist/autonomy/levels.d.ts.map +1 -0
  53. package/dist/autonomy/levels.js +51 -0
  54. package/dist/autonomy/levels.js.map +1 -0
  55. package/dist/conversations/store.d.ts +62 -0
  56. package/dist/conversations/store.d.ts.map +1 -0
  57. package/dist/conversations/store.js +0 -0
  58. package/dist/conversations/store.js.map +1 -0
  59. package/dist/identity/context.d.ts +8 -0
  60. package/dist/identity/context.d.ts.map +1 -1
  61. package/dist/identity/context.js +19 -4
  62. package/dist/identity/context.js.map +1 -1
  63. package/dist/identity/markdown.d.ts +38 -0
  64. package/dist/identity/markdown.d.ts.map +1 -0
  65. package/dist/identity/markdown.js +85 -0
  66. package/dist/identity/markdown.js.map +1 -0
  67. package/dist/index.d.ts +56 -5
  68. package/dist/index.d.ts.map +1 -1
  69. package/dist/index.js +30 -3
  70. package/dist/index.js.map +1 -1
  71. package/dist/prompts/render.d.ts +23 -0
  72. package/dist/prompts/render.d.ts.map +1 -0
  73. package/dist/prompts/render.js +35 -0
  74. package/dist/prompts/render.js.map +1 -0
  75. package/dist/prompts/seeds.d.ts +34 -0
  76. package/dist/prompts/seeds.d.ts.map +1 -0
  77. package/dist/prompts/seeds.js +166 -0
  78. package/dist/prompts/seeds.js.map +1 -0
  79. package/dist/prompts/store.d.ts +8 -0
  80. package/dist/prompts/store.d.ts.map +1 -0
  81. package/dist/prompts/store.js +153 -0
  82. package/dist/prompts/store.js.map +1 -0
  83. package/dist/prompts/types.d.ts +51 -0
  84. package/dist/prompts/types.d.ts.map +1 -0
  85. package/dist/prompts/types.js +24 -0
  86. package/dist/prompts/types.js.map +1 -0
  87. package/dist/providers/anthropic.d.ts +21 -3
  88. package/dist/providers/anthropic.d.ts.map +1 -1
  89. package/dist/providers/anthropic.js +60 -12
  90. package/dist/providers/anthropic.js.map +1 -1
  91. package/dist/providers/catalog.d.ts +41 -0
  92. package/dist/providers/catalog.d.ts.map +1 -0
  93. package/dist/providers/catalog.js +85 -0
  94. package/dist/providers/catalog.js.map +1 -0
  95. package/dist/providers/content-parts.d.ts +12 -0
  96. package/dist/providers/content-parts.d.ts.map +1 -0
  97. package/dist/providers/content-parts.js +18 -0
  98. package/dist/providers/content-parts.js.map +1 -0
  99. package/dist/providers/defaults.d.ts +15 -0
  100. package/dist/providers/defaults.d.ts.map +1 -0
  101. package/dist/providers/defaults.js +15 -0
  102. package/dist/providers/defaults.js.map +1 -0
  103. package/dist/providers/google.d.ts +16 -3
  104. package/dist/providers/google.d.ts.map +1 -1
  105. package/dist/providers/google.js +54 -12
  106. package/dist/providers/google.js.map +1 -1
  107. package/dist/providers/openai.d.ts +32 -4
  108. package/dist/providers/openai.d.ts.map +1 -1
  109. package/dist/providers/openai.js +114 -21
  110. package/dist/providers/openai.js.map +1 -1
  111. package/dist/providers/registry.d.ts +31 -20
  112. package/dist/providers/registry.d.ts.map +1 -1
  113. package/dist/providers/registry.js +49 -7
  114. package/dist/providers/registry.js.map +1 -1
  115. package/dist/providers/request-signal.d.ts +23 -0
  116. package/dist/providers/request-signal.d.ts.map +1 -0
  117. package/dist/providers/request-signal.js +26 -0
  118. package/dist/providers/request-signal.js.map +1 -0
  119. package/dist/providers/resolve.d.ts +13 -0
  120. package/dist/providers/resolve.d.ts.map +1 -0
  121. package/dist/providers/resolve.js +30 -0
  122. package/dist/providers/resolve.js.map +1 -0
  123. package/dist/providers/store.d.ts +70 -0
  124. package/dist/providers/store.d.ts.map +1 -0
  125. package/dist/providers/store.js +308 -0
  126. package/dist/providers/store.js.map +1 -0
  127. package/dist/providers/tool-names.d.ts +9 -0
  128. package/dist/providers/tool-names.d.ts.map +1 -0
  129. package/dist/providers/tool-names.js +56 -0
  130. package/dist/providers/tool-names.js.map +1 -0
  131. package/dist/providers/types.d.ts +78 -3
  132. package/dist/providers/types.d.ts.map +1 -1
  133. package/dist/rag/reference-documents/ingest.d.ts +22 -0
  134. package/dist/rag/reference-documents/ingest.d.ts.map +1 -0
  135. package/dist/rag/reference-documents/ingest.js +69 -0
  136. package/dist/rag/reference-documents/ingest.js.map +1 -0
  137. package/dist/rag/reference-documents/store.d.ts +23 -0
  138. package/dist/rag/reference-documents/store.d.ts.map +1 -0
  139. package/dist/rag/reference-documents/store.js +140 -0
  140. package/dist/rag/reference-documents/store.js.map +1 -0
  141. package/dist/rag/reference-documents/types.d.ts +52 -0
  142. package/dist/rag/reference-documents/types.d.ts.map +1 -0
  143. package/dist/rag/reference-documents/types.js +32 -0
  144. package/dist/rag/reference-documents/types.js.map +1 -0
  145. package/dist/runtime/loop.d.ts +29 -7
  146. package/dist/runtime/loop.d.ts.map +1 -1
  147. package/dist/runtime/loop.js +200 -42
  148. package/dist/runtime/loop.js.map +1 -1
  149. package/dist/runtime/types.d.ts +4 -3
  150. package/dist/runtime/types.d.ts.map +1 -1
  151. package/dist/site-plan/analyse-brief.d.ts +8 -0
  152. package/dist/site-plan/analyse-brief.d.ts.map +1 -1
  153. package/dist/site-plan/analyse-brief.js +18 -7
  154. package/dist/site-plan/analyse-brief.js.map +1 -1
  155. package/dist/site-plan/approval.d.ts +2 -2
  156. package/dist/site-plan/approval.d.ts.map +1 -1
  157. package/dist/site-plan/approval.js +34 -4
  158. package/dist/site-plan/approval.js.map +1 -1
  159. package/dist/site-plan/content-model.d.ts +14 -0
  160. package/dist/site-plan/content-model.d.ts.map +1 -1
  161. package/dist/site-plan/content-model.js +52 -8
  162. package/dist/site-plan/content-model.js.map +1 -1
  163. package/dist/site-plan/demo-content.js +2 -3
  164. package/dist/site-plan/demo-content.js.map +1 -1
  165. package/dist/site-plan/propose-plan.d.ts +10 -0
  166. package/dist/site-plan/propose-plan.d.ts.map +1 -1
  167. package/dist/site-plan/propose-plan.js +25 -1
  168. package/dist/site-plan/propose-plan.js.map +1 -1
  169. package/dist/site-plan/site-context.d.ts +81 -0
  170. package/dist/site-plan/site-context.d.ts.map +1 -0
  171. package/dist/site-plan/site-context.js +76 -0
  172. package/dist/site-plan/site-context.js.map +1 -0
  173. package/dist/site-plan/skin-candidates.d.ts +7 -0
  174. package/dist/site-plan/skin-candidates.d.ts.map +1 -1
  175. package/dist/site-plan/skin-candidates.js +6 -0
  176. package/dist/site-plan/skin-candidates.js.map +1 -1
  177. package/dist/site-plan/structural-gaps.d.ts +32 -0
  178. package/dist/site-plan/structural-gaps.d.ts.map +1 -0
  179. package/dist/site-plan/structural-gaps.js +77 -0
  180. package/dist/site-plan/structural-gaps.js.map +1 -0
  181. package/dist/site-plan/types.d.ts +7 -0
  182. package/dist/site-plan/types.d.ts.map +1 -1
  183. package/dist/skills/frontmatter.d.ts +19 -1
  184. package/dist/skills/frontmatter.d.ts.map +1 -1
  185. package/dist/skills/frontmatter.js +29 -5
  186. package/dist/skills/frontmatter.js.map +1 -1
  187. package/dist/skills/library.d.ts +133 -0
  188. package/dist/skills/library.d.ts.map +1 -0
  189. package/dist/skills/library.js +332 -0
  190. package/dist/skills/library.js.map +1 -0
  191. package/dist/skills/types.d.ts +8 -1
  192. package/dist/skills/types.d.ts.map +1 -1
  193. package/dist/skin/generate.d.ts +10 -0
  194. package/dist/skin/generate.d.ts.map +1 -1
  195. package/dist/skin/generate.js +43 -4
  196. package/dist/skin/generate.js.map +1 -1
  197. package/dist/theme-creator/propose-theme.d.ts +77 -0
  198. package/dist/theme-creator/propose-theme.d.ts.map +1 -0
  199. package/dist/theme-creator/propose-theme.js +228 -0
  200. package/dist/theme-creator/propose-theme.js.map +1 -0
  201. package/dist/tools/core/agent-delegate.d.ts +8 -5
  202. package/dist/tools/core/agent-delegate.d.ts.map +1 -1
  203. package/dist/tools/core/agent-delegate.js +16 -6
  204. package/dist/tools/core/agent-delegate.js.map +1 -1
  205. package/dist/tools/core/content-browse.d.ts +74 -0
  206. package/dist/tools/core/content-browse.d.ts.map +1 -0
  207. package/dist/tools/core/content-browse.js +63 -0
  208. package/dist/tools/core/content-browse.js.map +1 -0
  209. package/dist/tools/core/content-schema.d.ts +86 -0
  210. package/dist/tools/core/content-schema.d.ts.map +1 -0
  211. package/dist/tools/core/content-schema.js +83 -0
  212. package/dist/tools/core/content-schema.js.map +1 -0
  213. package/dist/tools/core/deps-scan.d.ts +25 -0
  214. package/dist/tools/core/deps-scan.d.ts.map +1 -0
  215. package/dist/tools/core/deps-scan.js +85 -0
  216. package/dist/tools/core/deps-scan.js.map +1 -0
  217. package/dist/tools/core/media.d.ts +18 -2
  218. package/dist/tools/core/media.d.ts.map +1 -1
  219. package/dist/tools/core/media.js +8 -2
  220. package/dist/tools/core/media.js.map +1 -1
  221. package/dist/tools/core/not-found-log.d.ts +44 -0
  222. package/dist/tools/core/not-found-log.d.ts.map +1 -0
  223. package/dist/tools/core/not-found-log.js +32 -0
  224. package/dist/tools/core/not-found-log.js.map +1 -0
  225. package/dist/tools/core/redirects.d.ts +51 -0
  226. package/dist/tools/core/redirects.d.ts.map +1 -0
  227. package/dist/tools/core/redirects.js +50 -0
  228. package/dist/tools/core/redirects.js.map +1 -0
  229. package/package.json +6 -4
@@ -13,10 +13,33 @@ export interface ProviderToolCall {
13
13
  readonly name: string;
14
14
  readonly input: Readonly<Record<string, unknown>>;
15
15
  }
16
+ /** A plain-text segment of a multimodal message. */
17
+ export interface ChatTextPart {
18
+ readonly type: 'text';
19
+ readonly text: string;
20
+ }
21
+ /**
22
+ * An inline image segment of a multimodal message. `data` is raw base64 —
23
+ * no `data:` URI prefix — so each adapter can format it however its own
24
+ * wire protocol wants it (a data URL for OpenAI, a bare base64 field for
25
+ * Anthropic and Google).
26
+ */
27
+ export interface ChatImagePart {
28
+ readonly type: 'image';
29
+ readonly mediaType: string;
30
+ readonly data: string;
31
+ }
32
+ export type ChatContentPart = ChatTextPart | ChatImagePart;
16
33
  export interface ChatMessage {
17
34
  readonly role: ChatRole;
18
- /** Absent (not empty-string) when a turn is tool calls with no accompanying text. */
19
- readonly content?: string;
35
+ /**
36
+ * Absent (not empty-string) when a turn is tool calls with no accompanying
37
+ * text. A plain `string` is the common case and every existing caller
38
+ * keeps compiling and behaving identically; an array of `ChatContentPart`
39
+ * lets a caller attach images alongside text (e.g. the Theme Creator
40
+ * agent handing a model a screenshot a user uploaded).
41
+ */
42
+ readonly content?: string | readonly ChatContentPart[];
20
43
  /** Set on an `assistant` message that requested tool calls. */
21
44
  readonly toolCalls?: readonly ProviderToolCall[];
22
45
  /** Set on a `tool` message: which call this is the result of. */
@@ -35,7 +58,14 @@ export interface ChatRequest {
35
58
  readonly system?: string;
36
59
  readonly messages: readonly ChatMessage[];
37
60
  readonly tools?: readonly ProviderToolSpec[];
38
- readonly maxTokens: number;
61
+ /**
62
+ * Absent lets the client fall back to its own configured
63
+ * `maxOutputTokens` (an admin-set property of the provider/model, not a
64
+ * literal a caller should be picking) — see `ProviderClient.maxOutputTokens`.
65
+ * A caller only sets this for a genuine, call-specific reason to differ
66
+ * from that default.
67
+ */
68
+ readonly maxTokens?: number;
39
69
  readonly temperature?: number;
40
70
  }
41
71
  export type StopReason = 'end_turn' | 'tool_use' | 'max_tokens' | 'stop_sequence';
@@ -58,6 +88,51 @@ export interface ChatOptions {
58
88
  export interface ProviderClient {
59
89
  readonly name: string;
60
90
  readonly model: string;
91
+ /**
92
+ * Whether this client can accept a `ChatImagePart` in a message's content.
93
+ * Absent means "unknown, assume no" — a caller building a multimodal
94
+ * message should check this before attaching an image, and degrade
95
+ * (text-only, with an explicit note) when it is not `true`.
96
+ */
97
+ readonly supportsVision?: boolean;
98
+ /**
99
+ * The completion budget every call through this client defaults to when
100
+ * a request does not set its own `maxTokens` — a property of *which
101
+ * model this is*, not of any one call site. A reasoning-tier model can
102
+ * spend thousands of tokens "thinking" before it ever writes a visible
103
+ * answer, and that reasoning counts against this same budget; a plain
104
+ * instruct model needs far less. This is why it lives on the provider
105
+ * (admin-configurable from `/admin/providers`, `resolve.ts` resolves it
106
+ * from `ProviderConfigStore`), not as a constant scattered across every
107
+ * caller — a real, reproduced bug (`docs`/changeset history: DeepSeek's
108
+ * `deepseek-v4-flash` hitting `finish_reason: "length"` with empty
109
+ * content at a too-low hardcoded ceiling) is exactly what a per-call
110
+ * hardcoded number cannot adapt to. Resolved adapters
111
+ * (`createAnthropicClient`/`createOpenAiClient`/`createGoogleClient`)
112
+ * always set this to a concrete number — the admin's value, or a built-in
113
+ * fallback when unset — so a caller never needs its own `?? literal`.
114
+ */
115
+ readonly maxOutputTokens?: number;
116
+ /**
117
+ * How many times a generate-validate-correct loop (skin generation, brief
118
+ * analysis, content-model/demo-content proposals, the base-theme choice)
119
+ * retries this client before giving up. Same reasoning as
120
+ * `maxOutputTokens`: a model that needs more coaxing to produce valid
121
+ * structured output benefits from more attempts, and that is a fact about
122
+ * the model, set by the admin who chose it — not a number a given call
123
+ * site should be guessing at.
124
+ */
125
+ readonly maxCorrectionAttempts?: number;
126
+ /**
127
+ * How long a single HTTP call to this provider is allowed to run before
128
+ * being aborted — both the raw request timeout each adapter applies via
129
+ * `requestSignalWithTimeout`, and the per-model-call timeout the LangGraph
130
+ * agent loop (`runtime/loop.ts`) enforces around `chat()`. A slower
131
+ * (often reasoning-tier) model genuinely needs more wall-clock time, not
132
+ * just more tokens; a fixed timeout picked without knowing which model an
133
+ * admin configured is the same class of mistake as a fixed token budget.
134
+ */
135
+ readonly requestTimeoutMs?: number;
61
136
  chat(request: ChatRequest, options?: ChatOptions): Promise<ChatResponse>;
62
137
  }
63
138
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":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import type { VectorStore } from '../vector/types.js';
4
+ export interface ReferenceDocumentIngestOptions {
5
+ readonly store: VectorStore;
6
+ readonly embeddings: EmbeddingProvider;
7
+ readonly siteId: string;
8
+ }
9
+ /**
10
+ * Chunks, embeds and stores one uploaded reference document under the
11
+ * reserved pseudo-collection (`types.ts`). `documentId` is the
12
+ * `ReferenceDocumentStore` row's own id — reusing it as the vector
13
+ * `entryId` is what lets `removeReferenceDocument` and a re-upload address
14
+ * exactly the chunks this document produced, the same way a content entry's
15
+ * id already does for `withVectorIndexing`.
16
+ */
17
+ export declare function ingestReferenceDocument(document: Pick<ExtractedDocument, 'filename' | 'text'>, documentId: string, options: ReferenceDocumentIngestOptions): Promise<{
18
+ readonly chunkCount: number;
19
+ }>;
20
+ /** Removes every chunk a document produced — an upload's own undo, and what a delete from the admin screen calls. */
21
+ export declare function removeReferenceDocumentVectors(store: VectorStore, siteId: string, documentId: string): Promise<void>;
22
+ //# sourceMappingURL=ingest.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ingest.d.ts","sourceRoot":"","sources":["../../../src/rag/reference-documents/ingest.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAA;AAGxE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAC/D,OAAO,KAAK,EAAgB,WAAW,EAAE,MAAM,oBAAoB,CAAA;AA4BnE,MAAM,WAAW,8BAA8B;IAC7C,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAA;IAC3B,QAAQ,CAAC,UAAU,EAAE,iBAAiB,CAAA;IACtC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CACxB;AAED;;;;;;;GAOG;AACH,wBAAsB,uBAAuB,CAC3C,QAAQ,EAAE,IAAI,CAAC,iBAAiB,EAAE,UAAU,GAAG,MAAM,CAAC,EACtD,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,8BAA8B,GACtC,OAAO,CAAC;IAAE,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;CAAE,CAAC,CA8B1C;AAED,qHAAqH;AACrH,wBAAsB,8BAA8B,CAClD,KAAK,EAAE,WAAW,EAClB,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,IAAI,CAAC,CAMf"}
@@ -0,0 +1,69 @@
1
+ import { chunkDocument } from '../chunking/chunk-document.js';
2
+ import { REFERENCE_DOCUMENT_COLLECTION, REFERENCE_DOCUMENT_LOCALE, REFERENCE_DOCUMENT_STATUS, } from './types.js';
3
+ /**
4
+ * The one real user of `chunkDocument` (L18 task 15) against an actual
5
+ * multi-chunk document — `withVectorIndexing`'s own `recordFor` deliberately
6
+ * uses one chunk per entry instead (see that file's comment: real chunking
7
+ * "is a piece of work of its own"). A reference document has no blocks to
8
+ * read, only the flat string `extractDocumentText` already produced, so this
9
+ * is that piece of work, scoped to exactly what an uploaded document needs:
10
+ * paragraphs standing in for blocks, a blank line standing in for the
11
+ * boundary between them, and nothing claiming to be a heading (a plain-text
12
+ * or a PDF extraction has no reliable way to tell one from a paragraph, so
13
+ * claiming otherwise would just fabricate section boundaries `chunkDocument`
14
+ * would then treat as if a human had marked them).
15
+ */
16
+ function paragraphsOf(text) {
17
+ return text
18
+ .split(/\n{2,}/u)
19
+ .map((paragraph) => paragraph.trim())
20
+ .filter((paragraph) => paragraph.length > 0)
21
+ .map((paragraph, index) => ({ id: String(index), text: paragraph }));
22
+ }
23
+ /**
24
+ * Chunks, embeds and stores one uploaded reference document under the
25
+ * reserved pseudo-collection (`types.ts`). `documentId` is the
26
+ * `ReferenceDocumentStore` row's own id — reusing it as the vector
27
+ * `entryId` is what lets `removeReferenceDocument` and a re-upload address
28
+ * exactly the chunks this document produced, the same way a content entry's
29
+ * id already does for `withVectorIndexing`.
30
+ */
31
+ export async function ingestReferenceDocument(document, documentId, options) {
32
+ const blocks = paragraphsOf(document.text);
33
+ if (blocks.length === 0)
34
+ return { chunkCount: 0 };
35
+ const chunks = chunkDocument({
36
+ documentId,
37
+ title: document.filename,
38
+ blocks,
39
+ });
40
+ if (chunks.length === 0)
41
+ return { chunkCount: 0 };
42
+ const vectors = await options.embeddings.embed(chunks.map((chunk) => chunk.text));
43
+ const records = [];
44
+ chunks.forEach((chunk, index) => {
45
+ const vector = vectors[index];
46
+ if (vector === undefined)
47
+ return;
48
+ records.push({
49
+ siteId: options.siteId,
50
+ collection: REFERENCE_DOCUMENT_COLLECTION,
51
+ entryId: documentId,
52
+ locale: REFERENCE_DOCUMENT_LOCALE,
53
+ status: REFERENCE_DOCUMENT_STATUS,
54
+ chunk,
55
+ vector,
56
+ });
57
+ });
58
+ await options.store.upsert(records);
59
+ return { chunkCount: records.length };
60
+ }
61
+ /** Removes every chunk a document produced — an upload's own undo, and what a delete from the admin screen calls. */
62
+ export async function removeReferenceDocumentVectors(store, siteId, documentId) {
63
+ await store.removeEntries({
64
+ siteId,
65
+ collection: REFERENCE_DOCUMENT_COLLECTION,
66
+ entryIds: [documentId],
67
+ });
68
+ }
69
+ //# sourceMappingURL=ingest.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ingest.js","sourceRoot":"","sources":["../../../src/rag/reference-documents/ingest.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAA;AAI7D,OAAO,EACL,6BAA6B,EAC7B,yBAAyB,EACzB,yBAAyB,GAC1B,MAAM,YAAY,CAAA;AAEnB;;;;;;;;;;;;GAYG;AACH,SAAS,YAAY,CAAC,IAAY;IAChC,OAAO,IAAI;SACR,KAAK,CAAC,SAAS,CAAC;SAChB,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC;SACpC,MAAM,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC;SAC3C,GAAG,CAAC,CAAC,SAAS,EAAE,KAAK,EAAE,EAAE,CAAC,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ACnC,OAAO,EAAE,UAAU,EAAE,OAAO,CAAC,MAAM,EAAE,CAAA;AACvC,CAAC;AAED,qHAAqH;AACrH,MAAM,CAAC,KAAK,UAAU,8BAA8B,CAClD,KAAkB,EAClB,MAAc,EACd,UAAkB;IAElB,MAAM,KAAK,CAAC,aAAa,CAAC;QACxB,MAAM;QACN,UAAU,EAAE,6BAA6B;QACzC,QAAQ,EAAE,CAAC,UAAU,CAAC;KACvB,CAAC,CAAA;AACJ,CAAC"}
@@ -0,0 +1,23 @@
1
+ import { type DatabaseHandle } from '@cogenta/core';
2
+ import type { DocumentFormat } from '../../documents/extract-text.js';
3
+ import type { ReferenceDocumentRecord } from './types.js';
4
+ export interface CreateReferenceDocumentInput {
5
+ readonly siteId: string;
6
+ readonly filename: string;
7
+ readonly format: DocumentFormat;
8
+ readonly characters: number;
9
+ readonly warnings: readonly string[];
10
+ readonly uploadedBy: string | null;
11
+ }
12
+ export interface ReferenceDocumentStore {
13
+ ensureTable(): Promise<void>;
14
+ list(siteId: string): Promise<readonly ReferenceDocumentRecord[]>;
15
+ get(siteId: string, id: string): Promise<ReferenceDocumentRecord | null>;
16
+ /** Inserted with `status: 'pending'` — indexing (embedding + vector upsert) happens after, and reports back via `markIndexed`/`markError`. */
17
+ create(input: CreateReferenceDocumentInput): Promise<ReferenceDocumentRecord>;
18
+ markIndexed(siteId: string, id: string, chunkCount: number, at: string): Promise<void>;
19
+ markError(siteId: string, id: string, message: string): Promise<void>;
20
+ remove(siteId: string, id: string): Promise<void>;
21
+ }
22
+ export declare function createReferenceDocumentStore(db: DatabaseHandle, now?: () => number): ReferenceDocumentStore;
23
+ //# sourceMappingURL=store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../../src/rag/reference-documents/store.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,cAAc,EAMpB,MAAM,eAAe,CAAA;AACtB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iC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@@ -0,0 +1,140 @@
1
+ import { CogentaError, identifier, newId, sql, unsafeRaw, } from '@cogenta/core';
2
+ /**
3
+ * Metadata for every reference document a site has uploaded — L22 task 4's
4
+ * "état clair de ce qui est indexé/en cours/en erreur". The vector store
5
+ * (`VectorStore`) holds the embedded chunks; this table holds the one row
6
+ * per upload that the admin screen actually renders a list from, because a
7
+ * `VectorStore` has no notion of "a document", only of chunks that happen to
8
+ * share an `entryId`.
9
+ *
10
+ * Column helpers are written out by hand rather than imported from
11
+ * `@cogenta/schema`'s `store/columns.ts`: that module is not part of
12
+ * `@cogenta/schema`'s public `exports` map (only `.` is), and `@cogenta/agents`
13
+ * may not deep-import another package's `src/`. Three columns' worth of
14
+ * per-dialect typing is not worth widening that package's public surface for.
15
+ */
16
+ const REFERENCE_DOCUMENTS_TABLE = 'cogenta_reference_documents';
17
+ function textColumn(dialect, length) {
18
+ return unsafeRaw(dialect === 'sqlite' ? 'text' : `varchar(${length})`);
19
+ }
20
+ function idColumn(dialect) {
21
+ if (dialect === 'postgres')
22
+ return unsafeRaw('uuid');
23
+ if (dialect === 'mysql')
24
+ return unsafeRaw('char(36)');
25
+ return unsafeRaw('text');
26
+ }
27
+ function timestampColumn(dialect) {
28
+ return textColumn(dialect, 32);
29
+ }
30
+ function integerColumn() {
31
+ return unsafeRaw('integer');
32
+ }
33
+ function toRecord(row) {
34
+ return {
35
+ id: row.id,
36
+ siteId: row.site_id,
37
+ filename: row.filename,
38
+ format: row.format,
39
+ characters: Number(row.characters),
40
+ chunkCount: Number(row.chunk_count),
41
+ status: row.status,
42
+ errorMessage: row.error_message,
43
+ warnings: JSON.parse(row.warnings),
44
+ uploadedAt: row.uploaded_at,
45
+ uploadedBy: row.uploaded_by,
46
+ indexedAt: row.indexed_at,
47
+ };
48
+ }
49
+ function notFound(id) {
50
+ return new CogentaError({
51
+ code: 'ASSIST_DOCUMENT_NOT_FOUND',
52
+ message: `No reference document "${id}" exists on this site.`,
53
+ hint: 'Check the id against GET /api/assistant/documents — it may already have been removed.',
54
+ details: { id },
55
+ });
56
+ }
57
+ export function createReferenceDocumentStore(db, now = Date.now) {
58
+ const d = db.dialect;
59
+ const table = identifier(REFERENCE_DOCUMENTS_TABLE, d);
60
+ return {
61
+ async ensureTable() {
62
+ await db.query(sql `
63
+ create table if not exists ${table} (
64
+ id ${idColumn(d)} not null primary key,
65
+ site_id ${textColumn(d, 500)} not null,
66
+ filename ${textColumn(d, 300)} not null,
67
+ format ${textColumn(d, 16)} not null,
68
+ characters ${integerColumn()} not null,
69
+ chunk_count ${integerColumn()} not null,
70
+ status ${textColumn(d, 16)} not null,
71
+ error_message ${textColumn(d, 2000)},
72
+ warnings ${textColumn(d, 4000)} not null,
73
+ uploaded_at ${timestampColumn(d)} not null,
74
+ uploaded_by ${idColumn(d)},
75
+ indexed_at ${timestampColumn(d)}
76
+ )`);
77
+ },
78
+ async list(siteId) {
79
+ // `id` (UUIDv7) breaks a tie on `uploaded_at` in the same direction —
80
+ // two uploads landing in the same millisecond still sort newest first,
81
+ // deterministically, rather than by whatever order SQLite feels like.
82
+ const result = await db.query(sql `
83
+ select * from ${table} where site_id = ${siteId} order by uploaded_at desc, id desc`);
84
+ return result.rows.map(toRecord);
85
+ },
86
+ async get(siteId, id) {
87
+ const result = await db.query(sql `
88
+ select * from ${table} where site_id = ${siteId} and id = ${id}`);
89
+ const row = result.rows[0];
90
+ return row === undefined ? null : toRecord(row);
91
+ },
92
+ async create(input) {
93
+ const id = newId(now);
94
+ const uploadedAt = new Date(now()).toISOString();
95
+ await db.query(sql `
96
+ insert into ${table}
97
+ (id, site_id, filename, format, characters, chunk_count, status,
98
+ error_message, warnings, uploaded_at, uploaded_by, indexed_at)
99
+ values (
100
+ ${id}, ${input.siteId}, ${input.filename}, ${input.format}, ${input.characters}, 0,
101
+ ${'pending'}, ${null}, ${JSON.stringify([...input.warnings])}, ${uploadedAt},
102
+ ${input.uploadedBy}, ${null}
103
+ )`);
104
+ return {
105
+ id,
106
+ siteId: input.siteId,
107
+ filename: input.filename,
108
+ format: input.format,
109
+ characters: input.characters,
110
+ chunkCount: 0,
111
+ status: 'pending',
112
+ errorMessage: null,
113
+ warnings: input.warnings,
114
+ uploadedAt,
115
+ uploadedBy: input.uploadedBy,
116
+ indexedAt: null,
117
+ };
118
+ },
119
+ async markIndexed(siteId, id, chunkCount, at) {
120
+ await db.query(sql `
121
+ update ${table}
122
+ set status = ${'indexed'}, chunk_count = ${chunkCount}, error_message = ${null}, indexed_at = ${at}
123
+ where site_id = ${siteId} and id = ${id}`);
124
+ },
125
+ async markError(siteId, id, message) {
126
+ await db.query(sql `
127
+ update ${table}
128
+ set status = ${'error'}, error_message = ${message}
129
+ where site_id = ${siteId} and id = ${id}`);
130
+ },
131
+ async remove(siteId, id) {
132
+ const existing = await db.query(sql `
133
+ select id from ${table} where site_id = ${siteId} and id = ${id}`);
134
+ if (existing.rows.length === 0)
135
+ throw notFound(id);
136
+ await db.query(sql `delete from ${table} where site_id = ${siteId} and id = ${id}`);
137
+ },
138
+ };
139
+ }
140
+ //# sourceMappingURL=store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"store.js","sourceRoot":"","sources":["../../../src/rag/reference-documents/store.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EAGZ,UAAU,EACV,KAAK,EAEL,GAAG,EACH,SAAS,GACV,MAAM,eAAe,CAAA;AAItB;;;;;;;;;;;;;GAaG;AAEH,MAAM,yBAAyB,GAAG,6BAA6B,CAAA;AAE/D,SAAS,UAAU,CAAC,OAAwB,EAAE,MAAc;IAC1D,OAAO,SAAS,CAAC,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,WAAW,MAAM,GAAG,CAAC,CAAA;AACxE,CAAC;AAED,SAAS,QAAQ,CAAC,OAAwB;IACxC,IAAI,OAAO,KAAK,UAAU;QAAE,OAAO,SAAS,CAAC,MAAM,CAAC,CAAA;IACpD,IAAI,OAAO,KAAK,OAAO;QAAE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;uBACC,OAAO,qBAAqB,OAAO;0BAChC,MAAM,aAAa,EAAE,EAAE,CAAC,CAAA;QAC9C,CAAC;QAED,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,EAAE;YACrB,MAAM,QAAQ,GAAG,MAAM,EAAE,CAAC,KAAK,CAAM,GAAG,CAAA;yBACrB,KAAK,oBAAoB,MAAM,aAAa,EAAE,EAAE,CAAC,CAAA;YACpE,IAAI,QAAQ,CAAC,IAAI,CAAC,MAAM,KAAK,CAAC;gBAAE,MAAM,QAAQ,CAAC,EAAE,CAAC,CAAA;YAClD,MAAM,EAAE,CAAC,KAAK,CAAC,GAAG,CAAA,eAAe,KAAK,oBAAoB,MAAM,aAAa,EAAE,EAAE,CAAC,CAAA;QACpF,CAAC;KACF,CAAA;AACH,CAAC"}
@@ -0,0 +1,52 @@
1
+ import type { DocumentFormat } from '../../documents/extract-text.js';
2
+ /**
3
+ * L22 task 4 — "un flux d'upload de documents additionnels", wired onto the
4
+ * existing extraction → chunking → vectorisation pipeline (L19/L18) rather
5
+ * than a second one.
6
+ *
7
+ * A reference document is not content: it has no collection, no locale
8
+ * variants, no draft/published lifecycle. It still needs a home in the
9
+ * vector index so `assist.chat` can retrieve it — `VectorRecord` requires a
10
+ * `collection`/`entryId`/`locale`/`status` (task 5's `VectorScope`), so this
11
+ * pseudo-collection name is the answer to "what collection is a reference
12
+ * document in?".
13
+ *
14
+ * `^_` can never collide with a real collection name:
15
+ * `defineCollection`'s own `COLLECTION_NAME_PATTERN` is
16
+ * `/^[a-z][a-z0-9_]*$/`, which requires a *letter* first. Starting with an
17
+ * underscore is therefore a name no `defineCollection` call can ever
18
+ * produce, on any site, without needing a registry or a reserved-word list
19
+ * kept in sync by hand.
20
+ */
21
+ export declare const REFERENCE_DOCUMENT_COLLECTION = "_reference_documents";
22
+ /** `locale` a reference document's chunks are stored under — it has no translations, so one sentinel value stands in for "not localised". */
23
+ export declare const REFERENCE_DOCUMENT_LOCALE = "und";
24
+ /**
25
+ * `status` a reference document's chunks are stored under. Reusing the
26
+ * content lifecycle's own `'published'` value (rather than inventing a new
27
+ * one) is what lets `assist.chat`'s hard-coded `status: 'published'` filter
28
+ * retrieve it with no change to that tool — a reference document is exactly
29
+ * as quotable as a published entry, the moment it finishes indexing.
30
+ */
31
+ export declare const REFERENCE_DOCUMENT_STATUS = "published";
32
+ export declare const REFERENCE_DOCUMENT_STATUSES: readonly ['pending', 'indexed', 'error'];
33
+ export type ReferenceDocumentStatus = (typeof REFERENCE_DOCUMENT_STATUSES)[number];
34
+ export interface ReferenceDocumentRecord {
35
+ readonly id: string;
36
+ readonly siteId: string;
37
+ readonly filename: string;
38
+ readonly format: DocumentFormat;
39
+ readonly characters: number;
40
+ /** Chunks actually embedded and stored. `0` until indexing finishes. */
41
+ readonly chunkCount: number;
42
+ readonly status: ReferenceDocumentStatus;
43
+ /** Set only when `status === 'error'`. */
44
+ readonly errorMessage: string | null;
45
+ /** `extractDocumentText`'s own warnings (e.g. "PDF page 4 has no text layer") — shown, never hidden. */
46
+ readonly warnings: readonly string[];
47
+ readonly uploadedAt: string;
48
+ readonly uploadedBy: string | null;
49
+ /** Set once indexing finishes successfully. */
50
+ readonly indexedAt: string | null;
51
+ }
52
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/rag/reference-documents/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAA;AAErE;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,6BAA6B,yBAAyB,CAAA;AAEnE,6IAA6I;AAC7I,eAAO,MAAM,yBAAyB,QAAQ,CAAA;AAE9C;;;;;;GAMG;AACH,eAAO,MAAM,yBAAyB,cAAc,CAAA;AAEpD,eAAO,MAAM,2BAA2B,YAAI,SAAS,EAAE,SAAS,EAAE,OAAO,CAAU,CAAA;AACnF,MAAM,MAAM,uBAAuB,GAAG,CAAC,OAAO,2BAA2B,CAAC,CAAC,MAAM,CAAC,CAAA;AAElF,MAAM,WAAW,uBAAuB;IACtC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;IACnB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IACzB,QAAQ,CAAC,MAAM,EAAE,cAAc,CAAA;IAC/B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;IAC3B,wEAAwE;IACxE,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;IAC3B,QAAQ,CAAC,MAAM,EAAE,uBAAuB,CAAA;IACxC,0CAA0C;IAC1C,QAAQ,CAAC,YAAY,EAAE,MAAM,GAAG,IAAI,CAAA;IACpC,wGAAwG;IACxG,QAAQ,CAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAA;IACpC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;IAC3B,QAAQ,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI,CAAA;IAClC,+CAA+C;IAC/C,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAA;CAClC"}
@@ -0,0 +1,32 @@
1
+ /**
2
+ * L22 task 4 — "un flux d'upload de documents additionnels", wired onto the
3
+ * existing extraction → chunking → vectorisation pipeline (L19/L18) rather
4
+ * than a second one.
5
+ *
6
+ * A reference document is not content: it has no collection, no locale
7
+ * variants, no draft/published lifecycle. It still needs a home in the
8
+ * vector index so `assist.chat` can retrieve it — `VectorRecord` requires a
9
+ * `collection`/`entryId`/`locale`/`status` (task 5's `VectorScope`), so this
10
+ * pseudo-collection name is the answer to "what collection is a reference
11
+ * document in?".
12
+ *
13
+ * `^_` can never collide with a real collection name:
14
+ * `defineCollection`'s own `COLLECTION_NAME_PATTERN` is
15
+ * `/^[a-z][a-z0-9_]*$/`, which requires a *letter* first. Starting with an
16
+ * underscore is therefore a name no `defineCollection` call can ever
17
+ * produce, on any site, without needing a registry or a reserved-word list
18
+ * kept in sync by hand.
19
+ */
20
+ export const REFERENCE_DOCUMENT_COLLECTION = '_reference_documents';
21
+ /** `locale` a reference document's chunks are stored under — it has no translations, so one sentinel value stands in for "not localised". */
22
+ export const REFERENCE_DOCUMENT_LOCALE = 'und';
23
+ /**
24
+ * `status` a reference document's chunks are stored under. Reusing the
25
+ * content lifecycle's own `'published'` value (rather than inventing a new
26
+ * one) is what lets `assist.chat`'s hard-coded `status: 'published'` filter
27
+ * retrieve it with no change to that tool — a reference document is exactly
28
+ * as quotable as a published entry, the moment it finishes indexing.
29
+ */
30
+ export const REFERENCE_DOCUMENT_STATUS = 'published';
31
+ export const REFERENCE_DOCUMENT_STATUSES = ['pending', 'indexed', 'error'];
32
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/rag/reference-documents/types.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,MAAM,6BAA6B,GAAG,sBAAsB,CAAA;AAEnE,6IAA6I;AAC7I,MAAM,CAAC,MAAM,yBAAyB,GAAG,KAAK,CAAA;AAE9C;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,WAAW,CAAA;AAEpD,MAAM,CAAC,MAAM,2BAA2B,GAAG,CAAC,SAAS,EAAE,SAAS,EAAE,OAAO,CAAU,CAAA"}
@@ -1,11 +1,33 @@
1
- import type { RunAgentLoopInput, RunResult } from './types.js';
1
+ import type { ProviderToolCall } from '../providers/types.js';
2
+ import type { ExecutableTool, RunAgentLoopInput, RunResult, ToolCallOutcome } from './types.js';
2
3
  /**
3
- * L4 task 2: one model call, tool dispatch, repeat with the three guards
4
- * the lot's own "pièges connus" call out by name: a step ceiling, repetition
5
- * detection, and per-call cost (usage) measured from the first line rather
6
- * than discovered later. Permission checking (task 4) and budgets (task 8)
7
- * wrap this from the outside; this loop only knows how to hold a
8
- * conversation with a model and the tools it was handed.
4
+ * L24 task 1's whole point, made concrete: this function knows nothing about
5
+ * autonomy, approval, or audit. It is handed whatever `ExecutableTool` its
6
+ * caller built, and calls `.execute()` on it nothing more. Contract C's R4
7
+ * ("un outil déclare ses permissions ; le runtime les vérifie — jamais un
8
+ * contrôle d'accès à l'intérieur d'un outil") extends unchanged to the graph
9
+ * era this way: the *tools* node below (the graph's own "inside a node" —
10
+ * see the task's own wording) is exactly this function wired to LangGraph,
11
+ * so it inherits the same "zero permission logic" property by construction.
12
+ * `packages/agents/test/runtime/loop.test.ts`'s "the graph node has no gate
13
+ * of its own" test calls this directly, once with a tool `withAutonomy`
14
+ * never touched (to show it *would* run unguarded) and once with the same
15
+ * tool wrapped (to show the run this package actually produces never can) —
16
+ * proving the gate lives in the tool object handed in, not in this function.
17
+ */
18
+ export declare function runTool(tool: ExecutableTool | undefined, call: ProviderToolCall, signal: AbortSignal): Promise<ToolCallOutcome>;
19
+ /**
20
+ * L4 task 2, migrated to LangGraph.js (L24 task 1): one model call, tool
21
+ * dispatch, repeat — with the same three guards as before (a step ceiling,
22
+ * repetition detection, per-call cost measured from the first line), now run
23
+ * as a two-node `StateGraph` (`buildAgentGraph` above) instead of a `for`
24
+ * loop. The public contract — `RunAgentLoopInput` in, `RunResult` out — is
25
+ * unchanged, so every existing caller (`agents/orchestrator.ts`,
26
+ * `subagents/run-subagent.ts`, `tools/core/agent-delegate.ts`,
27
+ * `assist/runtime.ts`, `eval/run-suite.ts`) needed no change at all.
28
+ * Permission checking (task 4, now `withAutonomy`) and budgets (task 8)
29
+ * still wrap this from the outside; this module still only knows how to
30
+ * hold a conversation with a model and the tools it was handed.
9
31
  */
10
32
  export declare function runAgentLoop(input: RunAgentLoopInput): Promise<RunResult>;
11
33
  //# sourceMappingURL=loop.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"loop.d.ts","sourceRoot":"","sources":["../../src/runtime/loop.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAEV,iBAAiB,EACjB,SAAS,EAGV,MAAM,YAAY,CAAA;AAkCnB;;;;;;;GAOG;AACH,wBAAsB,YAAY,CAAC,KAAK,EAAE,iBAAiB,GAAG,OAAO,CAAC,SAAS,CAAC,CAoG/E"}
1
+ {"version":3,"file":"loop.d.ts","sourceRoot":"","sources":["../../src/runtime/loop.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAe,gBAAgB,EAAc,MAAM,uBAAuB,CAAA;AAGtF,OAAO,KAAK,EACV,cAAc,EACd,iBAAiB,EACjB,SAAS,EAGT,eAAe,EAChB,MAAM,YAAY,CAAA;AAqBnB;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,OAAO,CAC3B,IAAI,EAAE,cAAc,GAAG,SAAS,EAChC,IAAI,EAAE,gBAAgB,EACtB,MAAM,EAAE,WAAW,GAClB,OAAO,CAAC,eAAe,CAAC,CAU1B;AA0MD;;;;;;;;;;;;GAYG;AACH,wBAAsB,YAAY,CAAC,KAAK,EAAE,iBAAiB,GAAG,OAAO,CAAC,SAAS,CAAC,CAyC/E"}