@itaila/archetype 0.3.30

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 (319) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +475 -0
  3. package/dist/audit/audit-persona.d.ts +163 -0
  4. package/dist/audit/audit-persona.d.ts.map +1 -0
  5. package/dist/audit/audit-persona.js +415 -0
  6. package/dist/audit/audit-persona.js.map +1 -0
  7. package/dist/audit/brain-reflection.d.ts +33 -0
  8. package/dist/audit/brain-reflection.d.ts.map +1 -0
  9. package/dist/audit/brain-reflection.js +148 -0
  10. package/dist/audit/brain-reflection.js.map +1 -0
  11. package/dist/audit/conversation-audit.d.ts +12 -0
  12. package/dist/audit/conversation-audit.d.ts.map +1 -0
  13. package/dist/audit/conversation-audit.js +76 -0
  14. package/dist/audit/conversation-audit.js.map +1 -0
  15. package/dist/audit/prompt-audit.d.ts +10 -0
  16. package/dist/audit/prompt-audit.d.ts.map +1 -0
  17. package/dist/audit/prompt-audit.js +153 -0
  18. package/dist/audit/prompt-audit.js.map +1 -0
  19. package/dist/audit/prompt-dump.d.ts +137 -0
  20. package/dist/audit/prompt-dump.d.ts.map +1 -0
  21. package/dist/audit/prompt-dump.js +269 -0
  22. package/dist/audit/prompt-dump.js.map +1 -0
  23. package/dist/audit/trace-integrity.d.ts +33 -0
  24. package/dist/audit/trace-integrity.d.ts.map +1 -0
  25. package/dist/audit/trace-integrity.js +109 -0
  26. package/dist/audit/trace-integrity.js.map +1 -0
  27. package/dist/audit/types.d.ts +92 -0
  28. package/dist/audit/types.d.ts.map +1 -0
  29. package/dist/audit/types.js +2 -0
  30. package/dist/audit/types.js.map +1 -0
  31. package/dist/audit/version.d.ts +14 -0
  32. package/dist/audit/version.d.ts.map +1 -0
  33. package/dist/audit/version.js +65 -0
  34. package/dist/audit/version.js.map +1 -0
  35. package/dist/brain.d.ts +7 -0
  36. package/dist/brain.d.ts.map +1 -0
  37. package/dist/brain.js +83 -0
  38. package/dist/brain.js.map +1 -0
  39. package/dist/builder/actions.d.ts +60 -0
  40. package/dist/builder/actions.d.ts.map +1 -0
  41. package/dist/builder/actions.js +257 -0
  42. package/dist/builder/actions.js.map +1 -0
  43. package/dist/builder/browser.d.ts +140 -0
  44. package/dist/builder/browser.d.ts.map +1 -0
  45. package/dist/builder/browser.js +232 -0
  46. package/dist/builder/browser.js.map +1 -0
  47. package/dist/builder/executor.d.ts +228 -0
  48. package/dist/builder/executor.d.ts.map +1 -0
  49. package/dist/builder/executor.js +1548 -0
  50. package/dist/builder/executor.js.map +1 -0
  51. package/dist/builder/index.d.ts +24 -0
  52. package/dist/builder/index.d.ts.map +1 -0
  53. package/dist/builder/index.js +24 -0
  54. package/dist/builder/index.js.map +1 -0
  55. package/dist/builder/node-test-discovery.d.ts +13 -0
  56. package/dist/builder/node-test-discovery.d.ts.map +1 -0
  57. package/dist/builder/node-test-discovery.js +45 -0
  58. package/dist/builder/node-test-discovery.js.map +1 -0
  59. package/dist/builder/sandbox.d.ts +172 -0
  60. package/dist/builder/sandbox.d.ts.map +1 -0
  61. package/dist/builder/sandbox.js +294 -0
  62. package/dist/builder/sandbox.js.map +1 -0
  63. package/dist/builder/workspace-files.d.ts +63 -0
  64. package/dist/builder/workspace-files.d.ts.map +1 -0
  65. package/dist/builder/workspace-files.js +190 -0
  66. package/dist/builder/workspace-files.js.map +1 -0
  67. package/dist/core/actions.d.ts +55 -0
  68. package/dist/core/actions.d.ts.map +1 -0
  69. package/dist/core/actions.js +311 -0
  70. package/dist/core/actions.js.map +1 -0
  71. package/dist/core/attachment-notes.d.ts +7 -0
  72. package/dist/core/attachment-notes.d.ts.map +1 -0
  73. package/dist/core/attachment-notes.js +38 -0
  74. package/dist/core/attachment-notes.js.map +1 -0
  75. package/dist/core/context.d.ts +10 -0
  76. package/dist/core/context.d.ts.map +1 -0
  77. package/dist/core/context.js +108 -0
  78. package/dist/core/context.js.map +1 -0
  79. package/dist/core/crud-prompt.d.ts +16 -0
  80. package/dist/core/crud-prompt.d.ts.map +1 -0
  81. package/dist/core/crud-prompt.js +268 -0
  82. package/dist/core/crud-prompt.js.map +1 -0
  83. package/dist/core/crud-schema.d.ts +12 -0
  84. package/dist/core/crud-schema.d.ts.map +1 -0
  85. package/dist/core/crud-schema.js +42 -0
  86. package/dist/core/crud-schema.js.map +1 -0
  87. package/dist/core/effective-config.d.ts +13 -0
  88. package/dist/core/effective-config.d.ts.map +1 -0
  89. package/dist/core/effective-config.js +33 -0
  90. package/dist/core/effective-config.js.map +1 -0
  91. package/dist/core/entities.d.ts +82 -0
  92. package/dist/core/entities.d.ts.map +1 -0
  93. package/dist/core/entities.js +116 -0
  94. package/dist/core/entities.js.map +1 -0
  95. package/dist/core/entity-helpers.d.ts +47 -0
  96. package/dist/core/entity-helpers.d.ts.map +1 -0
  97. package/dist/core/entity-helpers.js +122 -0
  98. package/dist/core/entity-helpers.js.map +1 -0
  99. package/dist/core/entity-registry.d.ts +47 -0
  100. package/dist/core/entity-registry.d.ts.map +1 -0
  101. package/dist/core/entity-registry.js +54 -0
  102. package/dist/core/entity-registry.js.map +1 -0
  103. package/dist/core/eq.d.ts +13 -0
  104. package/dist/core/eq.d.ts.map +1 -0
  105. package/dist/core/eq.js +41 -0
  106. package/dist/core/eq.js.map +1 -0
  107. package/dist/core/focus-context.d.ts +19 -0
  108. package/dist/core/focus-context.d.ts.map +1 -0
  109. package/dist/core/focus-context.js +46 -0
  110. package/dist/core/focus-context.js.map +1 -0
  111. package/dist/core/focus-mode-actions.d.ts +23 -0
  112. package/dist/core/focus-mode-actions.d.ts.map +1 -0
  113. package/dist/core/focus-mode-actions.js +74 -0
  114. package/dist/core/focus-mode-actions.js.map +1 -0
  115. package/dist/core/greeting.d.ts +10 -0
  116. package/dist/core/greeting.d.ts.map +1 -0
  117. package/dist/core/greeting.js +41 -0
  118. package/dist/core/greeting.js.map +1 -0
  119. package/dist/core/identity.d.ts +13 -0
  120. package/dist/core/identity.d.ts.map +1 -0
  121. package/dist/core/identity.js +54 -0
  122. package/dist/core/identity.js.map +1 -0
  123. package/dist/core/knowledge.d.ts +10 -0
  124. package/dist/core/knowledge.d.ts.map +1 -0
  125. package/dist/core/knowledge.js +40 -0
  126. package/dist/core/knowledge.js.map +1 -0
  127. package/dist/core/memory-actions.d.ts +38 -0
  128. package/dist/core/memory-actions.d.ts.map +1 -0
  129. package/dist/core/memory-actions.js +181 -0
  130. package/dist/core/memory-actions.js.map +1 -0
  131. package/dist/core/memory.d.ts +35 -0
  132. package/dist/core/memory.d.ts.map +1 -0
  133. package/dist/core/memory.js +168 -0
  134. package/dist/core/memory.js.map +1 -0
  135. package/dist/core/peer-actions.d.ts +15 -0
  136. package/dist/core/peer-actions.d.ts.map +1 -0
  137. package/dist/core/peer-actions.js +33 -0
  138. package/dist/core/peer-actions.js.map +1 -0
  139. package/dist/core/prompt-builder.d.ts +46 -0
  140. package/dist/core/prompt-builder.d.ts.map +1 -0
  141. package/dist/core/prompt-builder.js +543 -0
  142. package/dist/core/prompt-builder.js.map +1 -0
  143. package/dist/core/prompt-mode.d.ts +3 -0
  144. package/dist/core/prompt-mode.d.ts.map +1 -0
  145. package/dist/core/prompt-mode.js +6 -0
  146. package/dist/core/prompt-mode.js.map +1 -0
  147. package/dist/core/prompted-turn.d.ts +6 -0
  148. package/dist/core/prompted-turn.d.ts.map +1 -0
  149. package/dist/core/prompted-turn.js +48 -0
  150. package/dist/core/prompted-turn.js.map +1 -0
  151. package/dist/core/request-builder.d.ts +14 -0
  152. package/dist/core/request-builder.d.ts.map +1 -0
  153. package/dist/core/request-builder.js +64 -0
  154. package/dist/core/request-builder.js.map +1 -0
  155. package/dist/core/session-routing.d.ts +23 -0
  156. package/dist/core/session-routing.d.ts.map +1 -0
  157. package/dist/core/session-routing.js +59 -0
  158. package/dist/core/session-routing.js.map +1 -0
  159. package/dist/core/voice.d.ts +6 -0
  160. package/dist/core/voice.d.ts.map +1 -0
  161. package/dist/core/voice.js +30 -0
  162. package/dist/core/voice.js.map +1 -0
  163. package/dist/engine/chat.d.ts +45 -0
  164. package/dist/engine/chat.d.ts.map +1 -0
  165. package/dist/engine/chat.js +308 -0
  166. package/dist/engine/chat.js.map +1 -0
  167. package/dist/engine/continuity.d.ts +107 -0
  168. package/dist/engine/continuity.d.ts.map +1 -0
  169. package/dist/engine/continuity.js +320 -0
  170. package/dist/engine/continuity.js.map +1 -0
  171. package/dist/engine/crud.d.ts +62 -0
  172. package/dist/engine/crud.d.ts.map +1 -0
  173. package/dist/engine/crud.js +260 -0
  174. package/dist/engine/crud.js.map +1 -0
  175. package/dist/engine/side-effects.d.ts +93 -0
  176. package/dist/engine/side-effects.d.ts.map +1 -0
  177. package/dist/engine/side-effects.js +271 -0
  178. package/dist/engine/side-effects.js.map +1 -0
  179. package/dist/engine/staging.d.ts +29 -0
  180. package/dist/engine/staging.d.ts.map +1 -0
  181. package/dist/engine/staging.js +159 -0
  182. package/dist/engine/staging.js.map +1 -0
  183. package/dist/engine/working-set.d.ts +18 -0
  184. package/dist/engine/working-set.d.ts.map +1 -0
  185. package/dist/engine/working-set.js +246 -0
  186. package/dist/engine/working-set.js.map +1 -0
  187. package/dist/evals/action-contracts.d.ts +40 -0
  188. package/dist/evals/action-contracts.d.ts.map +1 -0
  189. package/dist/evals/action-contracts.js +208 -0
  190. package/dist/evals/action-contracts.js.map +1 -0
  191. package/dist/evals/brain-bloat.d.ts +39 -0
  192. package/dist/evals/brain-bloat.d.ts.map +1 -0
  193. package/dist/evals/brain-bloat.js +167 -0
  194. package/dist/evals/brain-bloat.js.map +1 -0
  195. package/dist/evals/brain-prescriptions.d.ts +30 -0
  196. package/dist/evals/brain-prescriptions.d.ts.map +1 -0
  197. package/dist/evals/brain-prescriptions.js +148 -0
  198. package/dist/evals/brain-prescriptions.js.map +1 -0
  199. package/dist/evals/cross-layer-duplicates.d.ts +49 -0
  200. package/dist/evals/cross-layer-duplicates.d.ts.map +1 -0
  201. package/dist/evals/cross-layer-duplicates.js +289 -0
  202. package/dist/evals/cross-layer-duplicates.js.map +1 -0
  203. package/dist/evals/entity-visibility.d.ts +28 -0
  204. package/dist/evals/entity-visibility.d.ts.map +1 -0
  205. package/dist/evals/entity-visibility.js +216 -0
  206. package/dist/evals/entity-visibility.js.map +1 -0
  207. package/dist/evals/index.d.ts +19 -0
  208. package/dist/evals/index.d.ts.map +1 -0
  209. package/dist/evals/index.js +11 -0
  210. package/dist/evals/index.js.map +1 -0
  211. package/dist/evals/judge.d.ts +22 -0
  212. package/dist/evals/judge.d.ts.map +1 -0
  213. package/dist/evals/judge.js +337 -0
  214. package/dist/evals/judge.js.map +1 -0
  215. package/dist/evals/operational-contract.d.ts +40 -0
  216. package/dist/evals/operational-contract.d.ts.map +1 -0
  217. package/dist/evals/operational-contract.js +115 -0
  218. package/dist/evals/operational-contract.js.map +1 -0
  219. package/dist/evals/prompt-content.d.ts +14 -0
  220. package/dist/evals/prompt-content.d.ts.map +1 -0
  221. package/dist/evals/prompt-content.js +104 -0
  222. package/dist/evals/prompt-content.js.map +1 -0
  223. package/dist/evals/runtime.d.ts +4 -0
  224. package/dist/evals/runtime.d.ts.map +1 -0
  225. package/dist/evals/runtime.js +197 -0
  226. package/dist/evals/runtime.js.map +1 -0
  227. package/dist/evals/sample-projects.d.ts +143 -0
  228. package/dist/evals/sample-projects.d.ts.map +1 -0
  229. package/dist/evals/sample-projects.js +644 -0
  230. package/dist/evals/sample-projects.js.map +1 -0
  231. package/dist/evals/types.d.ts +88 -0
  232. package/dist/evals/types.d.ts.map +1 -0
  233. package/dist/evals/types.js +2 -0
  234. package/dist/evals/types.js.map +1 -0
  235. package/dist/foundation/index.d.ts +158 -0
  236. package/dist/foundation/index.d.ts.map +1 -0
  237. package/dist/foundation/index.js +256 -0
  238. package/dist/foundation/index.js.map +1 -0
  239. package/dist/index.d.ts +223 -0
  240. package/dist/index.d.ts.map +1 -0
  241. package/dist/index.js +998 -0
  242. package/dist/index.js.map +1 -0
  243. package/dist/managed/autonomous-loop.d.ts +199 -0
  244. package/dist/managed/autonomous-loop.d.ts.map +1 -0
  245. package/dist/managed/autonomous-loop.js +451 -0
  246. package/dist/managed/autonomous-loop.js.map +1 -0
  247. package/dist/managed/conversation.d.ts +20 -0
  248. package/dist/managed/conversation.d.ts.map +1 -0
  249. package/dist/managed/conversation.js +40 -0
  250. package/dist/managed/conversation.js.map +1 -0
  251. package/dist/managed/knowledge.d.ts +7 -0
  252. package/dist/managed/knowledge.d.ts.map +1 -0
  253. package/dist/managed/knowledge.js +174 -0
  254. package/dist/managed/knowledge.js.map +1 -0
  255. package/dist/managed/memory-manager.d.ts +7 -0
  256. package/dist/managed/memory-manager.d.ts.map +1 -0
  257. package/dist/managed/memory-manager.js +18 -0
  258. package/dist/managed/memory-manager.js.map +1 -0
  259. package/dist/managed/memory-review.d.ts +45 -0
  260. package/dist/managed/memory-review.d.ts.map +1 -0
  261. package/dist/managed/memory-review.js +130 -0
  262. package/dist/managed/memory-review.js.map +1 -0
  263. package/dist/managed/storage.d.ts +2 -0
  264. package/dist/managed/storage.d.ts.map +1 -0
  265. package/dist/managed/storage.js +2 -0
  266. package/dist/managed/storage.js.map +1 -0
  267. package/dist/managed/work-history.d.ts +23 -0
  268. package/dist/managed/work-history.d.ts.map +1 -0
  269. package/dist/managed/work-history.js +31 -0
  270. package/dist/managed/work-history.js.map +1 -0
  271. package/dist/observability/index.d.ts +15 -0
  272. package/dist/observability/index.d.ts.map +1 -0
  273. package/dist/observability/index.js +15 -0
  274. package/dist/observability/index.js.map +1 -0
  275. package/dist/observability/render-run-markdown.d.ts +90 -0
  276. package/dist/observability/render-run-markdown.d.ts.map +1 -0
  277. package/dist/observability/render-run-markdown.js +231 -0
  278. package/dist/observability/render-run-markdown.js.map +1 -0
  279. package/dist/observability/turn-reporter.d.ts +20 -0
  280. package/dist/observability/turn-reporter.d.ts.map +1 -0
  281. package/dist/observability/turn-reporter.js +106 -0
  282. package/dist/observability/turn-reporter.js.map +1 -0
  283. package/dist/persona.d.ts +49 -0
  284. package/dist/persona.d.ts.map +1 -0
  285. package/dist/persona.js +287 -0
  286. package/dist/persona.js.map +1 -0
  287. package/dist/playbook/defaults.d.ts +25 -0
  288. package/dist/playbook/defaults.d.ts.map +1 -0
  289. package/dist/playbook/defaults.js +108 -0
  290. package/dist/playbook/defaults.js.map +1 -0
  291. package/dist/playbook/invariants.d.ts +244 -0
  292. package/dist/playbook/invariants.d.ts.map +1 -0
  293. package/dist/playbook/invariants.js +259 -0
  294. package/dist/playbook/invariants.js.map +1 -0
  295. package/dist/playbook/templates.d.ts +7 -0
  296. package/dist/playbook/templates.d.ts.map +1 -0
  297. package/dist/playbook/templates.js +437 -0
  298. package/dist/playbook/templates.js.map +1 -0
  299. package/dist/providers/gemini.d.ts +73 -0
  300. package/dist/providers/gemini.d.ts.map +1 -0
  301. package/dist/providers/gemini.js +536 -0
  302. package/dist/providers/gemini.js.map +1 -0
  303. package/dist/providers/types.d.ts +2 -0
  304. package/dist/providers/types.d.ts.map +1 -0
  305. package/dist/providers/types.js +2 -0
  306. package/dist/providers/types.js.map +1 -0
  307. package/dist/providers/zod-to-gemini.d.ts +8 -0
  308. package/dist/providers/zod-to-gemini.d.ts.map +1 -0
  309. package/dist/providers/zod-to-gemini.js +148 -0
  310. package/dist/providers/zod-to-gemini.js.map +1 -0
  311. package/dist/samples/pm-spec-agent.d.ts +22 -0
  312. package/dist/samples/pm-spec-agent.d.ts.map +1 -0
  313. package/dist/samples/pm-spec-agent.js +53 -0
  314. package/dist/samples/pm-spec-agent.js.map +1 -0
  315. package/dist/types.d.ts +920 -0
  316. package/dist/types.d.ts.map +1 -0
  317. package/dist/types.js +2 -0
  318. package/dist/types.js.map +1 -0
  319. package/package.json +68 -0
@@ -0,0 +1,920 @@
1
+ import type { z } from 'zod';
2
+ /** Configuration for a peer persona that this persona can consult mid-turn */
3
+ export interface PeerConfig {
4
+ /** The peer persona — any object with a chat() method (managed or raw engine wrapper) */
5
+ persona: {
6
+ chat: (input: ManagedChatInput | ChatInput) => Promise<ChatResult & {
7
+ conversationId?: string;
8
+ }>;
9
+ };
10
+ /** Build context for the peer based on the consulting persona's query and current context */
11
+ contextBuilder: (query: string, parentContext: Record<string, unknown>) => Promise<Record<string, unknown>>;
12
+ /** Human-readable description of what this peer does (injected into consultPeer action description) */
13
+ expertise?: string;
14
+ /** Resolve which conversation to use for the peer (default: auto from peer's adapter) */
15
+ conversationResolver?: () => Promise<string | undefined>;
16
+ }
17
+ /** Record of a single peer consultation that occurred mid-turn */
18
+ export interface PeerConsultation {
19
+ peer: string;
20
+ query: string;
21
+ response: string;
22
+ trace: TurnTrace;
23
+ durationMs: number;
24
+ }
25
+ /** Trace of a single action through the validation pipeline */
26
+ export interface TracedAction {
27
+ name: string;
28
+ params: Record<string, unknown>;
29
+ status: 'valid' | 'invalid' | 'repaired' | 'unknown_action';
30
+ error?: string;
31
+ }
32
+ /** Trace of a single CRUD action through validation and execution */
33
+ export interface TracedCrudAction {
34
+ operation: 'create' | 'update' | 'delete';
35
+ entity: string;
36
+ id?: string;
37
+ params: Record<string, unknown>;
38
+ status: 'valid' | 'invalid' | 'executed' | 'failed';
39
+ error?: string;
40
+ }
41
+ /** Trace of a domain action executed by app code */
42
+ export interface TracedDomainAction {
43
+ name: string;
44
+ params: Record<string, unknown>;
45
+ status: 'executed' | 'failed' | 'skipped';
46
+ error?: string;
47
+ durationMs?: number;
48
+ }
49
+ /**
50
+ * Structured trace of a single turn through the Archetype pipeline.
51
+ * Built incrementally: Layer 1 (parse/validate) fills parse + validation fields,
52
+ * Layer 2 (managed mode) fills execution fields, app code fills domainActions.
53
+ *
54
+ * Always present on ChatResult — structural, not opt-in.
55
+ */
56
+ export interface TurnTrace {
57
+ traceId: string;
58
+ /** Which persona generated this trace */
59
+ personaId?: string;
60
+ /** Links traces across personas in one user interaction */
61
+ correlationId?: string;
62
+ /** Provider/model that actually produced this turn. */
63
+ provider?: {
64
+ name: string;
65
+ requestedModel?: string;
66
+ model?: string;
67
+ requestFingerprint?: LLMRequestFingerprint;
68
+ attempts?: LLMProviderAttempt[];
69
+ };
70
+ /** Exact Archetype text request assembled before provider transport. */
71
+ llmRequest?: TracedLLMRequest;
72
+ startedAt: number;
73
+ completedAt?: number;
74
+ parseOk: boolean;
75
+ repairAttempted: boolean;
76
+ repairSucceeded?: boolean;
77
+ actions: TracedAction[];
78
+ crudActions: TracedCrudAction[];
79
+ executionResults: TracedCrudAction[];
80
+ domainActions: TracedDomainAction[];
81
+ /** Peer consultations that occurred mid-turn */
82
+ peerConsultations?: PeerConsultation[];
83
+ /** AI-written outcome notes (human-readable, for admin display) */
84
+ outcomeNotes: string[];
85
+ /** Errors from the SDK pipeline and app-level domain validation. Both push here. */
86
+ errors: string[];
87
+ }
88
+ export interface EntityConfig {
89
+ /** Zod schema for entity fields */
90
+ schema: z.ZodType;
91
+ /** Human-readable name (e.g., "Thread", "Forcing Function"). Defaults to capitalize(key). */
92
+ label?: string;
93
+ /** Which field to use as display title in annotations */
94
+ displayField?: string;
95
+ /** Description of what this entity represents — helps the AI understand when to create/update/delete */
96
+ description?: string;
97
+ /**
98
+ * When true, only `create` is expected for this entity — no update/delete.
99
+ * The entity-visibility audit skips the "must be visible in context with id"
100
+ * check since there is nothing to update or delete.
101
+ * Shorthand for `operations: ['create']`.
102
+ */
103
+ createOnly?: boolean;
104
+ /**
105
+ * The operations the host app actually implements for this entity.
106
+ * The prompt only advertises these, and validation rejects the rest —
107
+ * so the model can't be led into mutations that would fail at commit.
108
+ * Defaults to all three (or to ['create'] when createOnly is set).
109
+ */
110
+ operations?: ReadonlyArray<'create' | 'update' | 'delete'>;
111
+ }
112
+ export interface CrudAction {
113
+ operation: 'create' | 'update' | 'delete';
114
+ entity: string;
115
+ id?: string;
116
+ params?: Record<string, unknown>;
117
+ }
118
+ export interface PersonaIdentity {
119
+ /** Display name of the persona (e.g. "Coach", "Guide") */
120
+ name: string;
121
+ /** Domain expertise areas the persona weaves together */
122
+ expertise: string[];
123
+ /** Relationship descriptor (e.g. "trusted thinking partner", "warm companion") */
124
+ relationship: string;
125
+ /** What this persona ultimately serves */
126
+ northStar: string;
127
+ /** Optional, minimal boundary. Use sparingly; omit unless truly load-bearing. */
128
+ scopeBoundary?: string;
129
+ /**
130
+ * The keystone instruction — "What is the single most impactful thing
131
+ * you could say right now?" Customizable per domain.
132
+ */
133
+ keystone?: string;
134
+ }
135
+ export interface PromptScaffoldConfig {
136
+ /**
137
+ * Optional relationship/presence hook appended to the identity block.
138
+ * Set to false to omit it entirely, or provide a custom string.
139
+ */
140
+ relationalPreamble?: string | false;
141
+ /**
142
+ * Optional momentum block appended near the end of the prompt.
143
+ * Set to false to omit it entirely, or provide a custom string.
144
+ */
145
+ momentumBlock?: string | false;
146
+ /**
147
+ * Optional come-back test appended near the end of the prompt.
148
+ * Set to false to omit it entirely, or provide a custom string.
149
+ */
150
+ comeBackTest?: string | false;
151
+ }
152
+ export type PromptMode = 'conversation' | 'operational' | 'focus';
153
+ export type PromptedTurnKind = 'operational' | 'proactive-conversation';
154
+ export type PromptOrigin = 'user' | 'app';
155
+ export type PromptContractStyle = 'full' | 'lean';
156
+ export interface BrainFileReference {
157
+ source: 'file';
158
+ path: string;
159
+ }
160
+ export interface BrainMarkdownReference {
161
+ source: 'markdown';
162
+ markdown: string;
163
+ path?: string;
164
+ }
165
+ export interface LoadedBrainArtifact {
166
+ source: 'loaded';
167
+ markdown: string;
168
+ metadata: Record<string, string>;
169
+ sections: Record<string, string>;
170
+ sourcePath?: string;
171
+ }
172
+ export type PersonaBrain = BrainFileReference | BrainMarkdownReference | LoadedBrainArtifact;
173
+ export type VoiceTone = 'direct' | 'warm' | 'balanced';
174
+ export type VoiceStyle = 'educator' | 'quick';
175
+ export type VoiceMedium = 'mobile-chat' | 'desktop-panel' | 'email-async';
176
+ export interface VoiceConfig {
177
+ tone: VoiceTone;
178
+ style: VoiceStyle;
179
+ medium?: VoiceMedium;
180
+ /** Custom formatting instructions (markdown, emoji, etc.) — appended to voice block */
181
+ formatting?: string;
182
+ }
183
+ export type ActionConfidence = 'low' | 'medium' | 'high';
184
+ export type ActionLayer = 'meaning' | 'transport';
185
+ export type WorkingDeltaReviewState = 'accepted' | 'pending' | 'rejected' | 'superseded';
186
+ export type WorkingDeltaCommitState = 'not_required' | 'ready' | 'committed' | 'failed';
187
+ export type WorkingSetReviewDecision = 'accept' | 'reject';
188
+ export type StagingModel = 'legacy-batch' | 'working-set';
189
+ export interface ActionDefinition {
190
+ /** Behavioral description — this IS a prompt (guides when to use) */
191
+ description: string;
192
+ /** Zod schema for the action's parameters */
193
+ schema: z.ZodType;
194
+ /** Optional model-facing example params when schema-derived examples would be misleading. */
195
+ exampleParams?: unknown;
196
+ /** Confidence threshold: low = just do it, medium = mention, high = confirm */
197
+ confidence: ActionConfidence;
198
+ /** Meaning-layer deltas become the current draft; transport-layer deltas require commit */
199
+ layer?: ActionLayer;
200
+ /** Default working-set review state when this action is staged */
201
+ defaultReviewState?: Extract<WorkingDeltaReviewState, 'accepted' | 'pending'>;
202
+ /** Commit behavior when this action is staged */
203
+ commitMode?: WorkingDeltaCommitState | 'explicit' | 'immediate';
204
+ /** Optional identity for supersession; same target replaces the prior accepted delta */
205
+ targetKey?: (validatedParams: Record<string, unknown>) => string | null;
206
+ }
207
+ export type ContextFormat = 'list' | 'block' | 'kv';
208
+ export interface ContextInputDefinition {
209
+ /** Label shown in the prompt (e.g. "OPEN THREADS") */
210
+ label: string;
211
+ /** One-line explanation of what this block is for and how the model should use it. */
212
+ intent?: string;
213
+ /** How to format the data */
214
+ format?: ContextFormat;
215
+ /** Character budget for this block (memory uses this) */
216
+ budget?: number;
217
+ /** Priority strategy for budget-constrained blocks */
218
+ prioritize?: 'pinned-first' | 'recent-first';
219
+ /** Priority level — 'critical' items get emphasized in prompt */
220
+ priority?: 'normal' | 'critical';
221
+ /** When true, include entity IDs in the prompt for AI-driven update/delete */
222
+ includeIds?: boolean;
223
+ }
224
+ export interface EQConfig {
225
+ /** Continuity: trust what already landed and look for the next layer unless repetition is genuinely needed */
226
+ frequencyRule?: boolean;
227
+ /** Autonomy respect: let the user lead, don't over-prescribe */
228
+ autonomyRespect?: boolean;
229
+ /** Qualitative first: default to qualitative language, give numbers when asked */
230
+ qualitativeFirst?: boolean;
231
+ /** Coherence: flag contradictions with earlier statements, lead with the shift */
232
+ coherence?: boolean;
233
+ /** Expert judgment: own the responsibility of expert recommendations, don't fill gaps with assumptions */
234
+ expertJudgment?: boolean;
235
+ }
236
+ export interface Memory {
237
+ id: string;
238
+ content: string;
239
+ category: string;
240
+ pinned?: boolean;
241
+ createdAt?: string;
242
+ /** Memory scope: 'user' for user-specific, 'craft' for professional growth */
243
+ scope?: 'user' | 'craft';
244
+ /** Where this memory came from: user-stated, agent-inferred, or agent-suggested */
245
+ source?: 'user' | 'inferred' | 'suggested';
246
+ /** Time horizon: 'durable' for reliable truths, 'tentative' for still-forming patterns, 'temporary' for situation-bound facts. */
247
+ stability?: 'durable' | 'tentative' | 'temporary';
248
+ /** Compact situational frame when the memory needs just enough context to stay interpretable */
249
+ contextHint?: string;
250
+ }
251
+ export interface MemoryConfig {
252
+ /** Enable memory prompt injection + extraction (default: true when present) */
253
+ enabled?: boolean;
254
+ /** Include memory IDs in prompt so AI can reference them for update/delete */
255
+ includeIds?: boolean;
256
+ /** Character budget for memory block in prompt */
257
+ budget?: number;
258
+ /**
259
+ * Domain-specific memory categories with descriptions.
260
+ * Keys are category names, values are human-readable descriptions.
261
+ * Injected into saveMemory action description and retrospective prompts
262
+ * so the LLM categorizes memories using domain-aware language.
263
+ *
264
+ * Example: { preference: 'Dietary preferences, food likes/dislikes', routine: 'Eating patterns, meal timing' }
265
+ */
266
+ categories?: Record<string, string>;
267
+ /**
268
+ * Explain what this persona's memory is for across future conversations.
269
+ * This should paint the horizon and intent, not prescribe brittle extraction rules.
270
+ */
271
+ purpose?: string;
272
+ }
273
+ export interface KnowledgeDocument {
274
+ id: string;
275
+ title: string;
276
+ content: string;
277
+ summary?: string;
278
+ tags?: string[];
279
+ status?: 'approved' | 'provisional' | 'draft' | 'archived';
280
+ updatedAt?: string;
281
+ path?: string;
282
+ }
283
+ export interface KnowledgeConfig {
284
+ /** Enable knowledge prompt injection when knowledge documents are provided */
285
+ enabled?: boolean;
286
+ /** Character budget for the knowledge block in prompt */
287
+ budget?: number;
288
+ /** Soft cap on retrieved documents for one turn */
289
+ maxDocuments?: number;
290
+ /** Optional prompt label override */
291
+ label?: string;
292
+ /** Explain what this persona should use shared knowledge for */
293
+ purpose?: string;
294
+ }
295
+ export interface KnowledgeSearchInput {
296
+ query: string;
297
+ budget?: number;
298
+ maxDocuments?: number;
299
+ }
300
+ export interface KnowledgeAdapter {
301
+ searchDocuments(input: KnowledgeSearchInput): Promise<KnowledgeDocument[]>;
302
+ getDocument?(id: string): Promise<KnowledgeDocument | null>;
303
+ }
304
+ export interface CraftMemoryConfig {
305
+ /** Enable craft memory — professional growth observations scoped to the persona */
306
+ enabled?: boolean;
307
+ /** Character budget for craft memory block in prompt (default: 3000) */
308
+ budget?: number;
309
+ /** Domain-specific categories for craft observations */
310
+ categories?: Record<string, string>;
311
+ /** Explain what craft memory captures for this persona */
312
+ purpose?: string;
313
+ }
314
+ export interface DiagnosticsConfig {
315
+ /** Enable the diagnostics channel — surfaces setup tensions to the developer */
316
+ enabled?: boolean;
317
+ }
318
+ export interface ApprovalConfig {
319
+ /**
320
+ * 'propose' — AI proposes actions, user confirms before execution.
321
+ * 'yolo' — actions execute immediately (current default behavior).
322
+ *
323
+ * ActionConfidence interacts with mode:
324
+ * - 'low' always auto-executes (even in propose mode)
325
+ * - 'medium' follows the mode setting
326
+ * - 'high' always proposes (even in yolo mode)
327
+ */
328
+ mode: 'propose' | 'yolo';
329
+ }
330
+ export interface StagingConfig {
331
+ /** Legacy batch review or working-set semantics */
332
+ model?: StagingModel;
333
+ }
334
+ export type StagedActionStatus = 'pending' | 'accepted' | 'rejected';
335
+ export interface StagedAction {
336
+ index: number;
337
+ action: ParsedAction;
338
+ validatedParams: Record<string, unknown>;
339
+ annotation: string;
340
+ status: StagedActionStatus;
341
+ }
342
+ export interface StagedBatch {
343
+ id: string;
344
+ actions: StagedAction[];
345
+ createdAt: string;
346
+ }
347
+ export interface BatchSummary {
348
+ total: number;
349
+ accepted: number;
350
+ rejected: number;
351
+ pending: number;
352
+ acceptedLabels: string[];
353
+ rejectedLabels: string[];
354
+ }
355
+ export interface WorkingDelta {
356
+ id: string;
357
+ action: ParsedAction;
358
+ validatedParams: Record<string, unknown>;
359
+ annotation: string;
360
+ layer: ActionLayer;
361
+ reviewState: WorkingDeltaReviewState;
362
+ commitState: WorkingDeltaCommitState;
363
+ targetKey?: string | null;
364
+ supersedes?: string;
365
+ createdAt: string;
366
+ updatedAt: string;
367
+ error?: string;
368
+ }
369
+ export interface WorkingSet {
370
+ id: string;
371
+ deltas: WorkingDelta[];
372
+ createdAt: string;
373
+ updatedAt: string;
374
+ }
375
+ export interface WorkingSetSummary {
376
+ total: number;
377
+ accepted: number;
378
+ pending: number;
379
+ rejected: number;
380
+ superseded: number;
381
+ ready: number;
382
+ committed: number;
383
+ failed: number;
384
+ }
385
+ export interface Message {
386
+ role: 'user' | 'assistant' | 'system';
387
+ content: string;
388
+ /** Stringified JSON of actions taken (for annotation in history) */
389
+ actionsJson?: string | null;
390
+ /** Whether this is a note/divider (not sent to LLM) */
391
+ isNote?: boolean;
392
+ /** App-specific metadata (e.g. userId, mealId). Carried through by the SDK, not interpreted. */
393
+ metadata?: Record<string, unknown>;
394
+ createdAt?: string;
395
+ }
396
+ export interface Conversation {
397
+ id: string;
398
+ trigger: string;
399
+ metadata?: Record<string, unknown>;
400
+ createdAt: string;
401
+ endedAt?: string | null;
402
+ }
403
+ export interface PersonaConfig {
404
+ identity: PersonaIdentity;
405
+ voice: VoiceConfig;
406
+ /** Optional portable role brain loaded from markdown. */
407
+ brain?: PersonaBrain;
408
+ /** Optional prompt scaffold overrides for identity/playbook framing. */
409
+ promptScaffold?: PromptScaffoldConfig;
410
+ /** Domain-specific methodology — locked, not user-editable */
411
+ methodology?: string;
412
+ /** Personal directives — editable by the user */
413
+ directives?: {
414
+ default: string;
415
+ editable?: boolean;
416
+ };
417
+ /** First-meeting scene — paints the situation for discovery, no prescriptions */
418
+ discovery?: string;
419
+ /** Entity definitions — each entity gets full CRUD (create/update/delete) automatically */
420
+ entities?: Record<string, EntityConfig>;
421
+ /** Structured actions the persona can take */
422
+ actions?: Record<string, ActionDefinition>;
423
+ /** Context inputs injected into the system prompt */
424
+ contextInputs?: Record<string, ContextInputDefinition>;
425
+ /** EQ configuration */
426
+ eq?: EQConfig;
427
+ /** Memory configuration — controls extraction, CRUD, and prompt injection */
428
+ memory?: MemoryConfig;
429
+ /** Queryable durable reference material — capabilities, posture, policies, docs */
430
+ knowledge?: KnowledgeConfig;
431
+ /** Craft memory — professional growth observations scoped to the persona, not the user */
432
+ craftMemory?: CraftMemoryConfig;
433
+ /** Diagnostics channel — surfaces setup tensions to the developer */
434
+ diagnostics?: DiagnosticsConfig;
435
+ /** Approval model for side-effect execution */
436
+ approval?: ApprovalConfig;
437
+ /** Staging model for multi-turn working drafts */
438
+ staging?: StagingConfig;
439
+ /** LLM provider to use */
440
+ provider: LLMProvider;
441
+ /** Override description for the followUps field in the response schema */
442
+ followUpsDescription?: string;
443
+ }
444
+ export interface ChatAttachment {
445
+ type: 'image';
446
+ mimeType: string;
447
+ data: string;
448
+ }
449
+ export interface ChatParticipant {
450
+ /** Stable id used by ledgers/apps, e.g. "pm", "builder", "user". */
451
+ id: string;
452
+ /** Human-readable participant label shown to the model. */
453
+ label: string;
454
+ /** Compact factual role in this interaction. */
455
+ description?: string;
456
+ }
457
+ export interface ChatSessionFrame {
458
+ /** Stable actor id for the persona producing this turn. */
459
+ actorId?: string;
460
+ /** Where this turn's visible message will land. */
461
+ visibleTo?: string;
462
+ /** Other relevant participants in this interaction. */
463
+ participants?: ChatParticipant[];
464
+ /** Compact factual reason this interaction exists. */
465
+ purpose?: string;
466
+ }
467
+ /** Pre-commit validation for CRUD proposals. Return error strings to reject, null to accept. */
468
+ export type CrudValidationFn = (actions: CrudAction[]) => string[] | null;
469
+ export interface ChatInput {
470
+ /** The user's message */
471
+ message: string;
472
+ /** Conversation history (legacy app-managed path). Prefer turnLedger when turns have action outcomes. */
473
+ history?: Array<{
474
+ role: 'user' | 'assistant';
475
+ content: string;
476
+ }>;
477
+ /**
478
+ * Archetype-owned turn ledger. When provided, Archetype renders model
479
+ * history from visible messages plus hidden factual outcomes, so apps do
480
+ * not have to manually stitch action results into chat history.
481
+ */
482
+ turnLedger?: TurnLedgerEntry[];
483
+ /** Actor id/name of the persona making this call; used to map ledger turns to assistant/user roles. */
484
+ turnLedgerActorId?: string;
485
+ /** Current turn number for rendering time-decaying turn-ledger action results. */
486
+ turnLedgerCurrentTurn?: number;
487
+ /** Context data keyed by contextInput name */
488
+ context?: Record<string, unknown>;
489
+ /** Which persona is making this call (for trace correlation) */
490
+ personaId?: string;
491
+ /** Links traces across personas in one user interaction */
492
+ correlationId?: string;
493
+ /** Memories to inject */
494
+ memories?: Memory[];
495
+ /** Durable knowledge documents to inject */
496
+ knowledgeDocuments?: KnowledgeDocument[];
497
+ /** Craft memories (persona-scoped professional growth) */
498
+ craftMemories?: Memory[];
499
+ /** User's timezone (IANA) */
500
+ timezone?: string;
501
+ /** Optional explicit timestamp for prompt rendering and deterministic reviews */
502
+ promptNow?: Date | string;
503
+ /** Override directives for this call */
504
+ directives?: string | null;
505
+ /** Additional system prompt sections */
506
+ extraSystemSections?: string[];
507
+ /** Final system prompt sections appended after the standard close. */
508
+ tailSystemSections?: string[];
509
+ /** Which prompt scaffold to use for this turn. */
510
+ promptMode?: PromptMode;
511
+ /** Whether this turn was initiated by a person or by the app/runtime. */
512
+ promptOrigin?: PromptOrigin;
513
+ /** Optional per-turn prompt scaffold overrides. */
514
+ promptScaffold?: PromptScaffoldConfig;
515
+ /** User identity string (e.g. "Alex, CEO of Acme") */
516
+ userIdentity?: string;
517
+ /** Last message timestamp — for greeting/staleness detection */
518
+ lastMessageAt?: Date | null;
519
+ /** Multimodal attachments (e.g. images) */
520
+ attachments?: ChatAttachment[];
521
+ /** Archetype-rendered interaction frame: who is speaking, who can see the message, and why this session exists. */
522
+ session?: ChatSessionFrame;
523
+ /** Locale code (e.g. 'he', 'en') — injected as language instruction in prompt */
524
+ locale?: string;
525
+ /** Current conversation-scoped working set for stateless integrations */
526
+ workingSet?: WorkingSet | null;
527
+ /** Prompt-facing action/entity contract verbosity. */
528
+ contractStyle?: PromptContractStyle;
529
+ /** Pre-commit CRUD validation. If provided, the SDK validates proposals and retries once on failure. */
530
+ crudValidation?: CrudValidationFn;
531
+ /** Max CRUD validation retries (default: 1) */
532
+ crudValidationRetries?: number;
533
+ }
534
+ export interface ParsedAction {
535
+ name: string;
536
+ params: Record<string, unknown>;
537
+ confidence: ActionConfidence;
538
+ }
539
+ export interface TurnLedgerActionOutcome {
540
+ /** Executor metadata used to build compact narration; do not raw-dump params into model continuity. */
541
+ action?: Pick<ParsedAction, 'name' | 'params'>;
542
+ /** Factual note shown to future model turns. */
543
+ outcomeNote?: string | null;
544
+ /** Full result text shown while the outcome is still fresh. */
545
+ resultText?: string | null;
546
+ /** Number of future turns that should continue seeing resultText. */
547
+ resultTurns?: number;
548
+ /** Replacement text after resultText ages out. */
549
+ staleText?: string | null;
550
+ /** Short raw result fallback. Large payloads should not be placed here. */
551
+ text?: string | null;
552
+ status?: string;
553
+ success?: boolean;
554
+ error?: string;
555
+ annotation?: string;
556
+ }
557
+ export interface TurnLedgerEntry {
558
+ /** Monotonic turn number used to age action outcomes. */
559
+ turn?: number;
560
+ /** Stable actor id/name, e.g. "pm", "builder", "user". */
561
+ actorId?: string;
562
+ /** Fallback role when no perspective actor is available. */
563
+ role?: 'user' | 'assistant';
564
+ /** User-visible text for this turn. */
565
+ message: string;
566
+ /** AI-written outcome notes from the model response. */
567
+ outcomeNotes?: string[];
568
+ /** Executor/action outcomes. Archetype renders these into hidden model continuity. */
569
+ actionOutcomes?: TurnLedgerActionOutcome[];
570
+ /** Debug/UI action annotations. Stripped before future model turns. */
571
+ actionAnnotations?: string[];
572
+ /** Compact function-call references for native function-calling history. */
573
+ actionsForHistory?: Array<Pick<ParsedAction, 'name' | 'params'>>;
574
+ }
575
+ export interface ChatResult {
576
+ /** The persona's conversational response */
577
+ message: string;
578
+ /** Structured actions proposed/taken */
579
+ actions: ParsedAction[];
580
+ /** CRUD actions on declared entities */
581
+ crudActions?: CrudAction[];
582
+ /** Optional compact carry-forward notes about uploaded attachments */
583
+ attachmentNotes?: string[];
584
+ /** Follow-up suggestions */
585
+ followUps?: string[];
586
+ /** Action annotations for history storage */
587
+ annotations?: string[];
588
+ /** Raw LLM response (for debugging) */
589
+ raw?: string;
590
+ /** Updated working set when staging.model = 'working-set' */
591
+ workingSet?: WorkingSet;
592
+ /** Summary counts for the working set */
593
+ workingSetSummary?: WorkingSetSummary;
594
+ /** Diagnostics surfaced by the AI about setup tensions (developer-facing) */
595
+ diagnostics?: string[];
596
+ /** AI-written outcome notes for history awareness (injected as ---outcomes: marker) */
597
+ outcomeNotes?: string[];
598
+ /** Pipeline trace for this turn — always present */
599
+ trace: TurnTrace;
600
+ }
601
+ export interface RetrospectActionResult {
602
+ name: string;
603
+ status: 'executed' | 'proposed' | 'failed' | 'no_op';
604
+ error?: string;
605
+ }
606
+ export interface RetrospectResult {
607
+ /** @deprecated Legacy action-based memory mutations. Use crudActions instead. */
608
+ actions: ParsedAction[];
609
+ /** Memory CRUD actions inferred from recent behavior */
610
+ crudActions?: CrudAction[];
611
+ /** Managed mode may attach execution outcomes */
612
+ results?: RetrospectActionResult[];
613
+ /** Raw LLM response (for debugging) */
614
+ raw?: string;
615
+ /** Diagnostics surfaced by the AI about setup tensions (developer-facing) */
616
+ diagnostics?: string[];
617
+ /** Pipeline trace for this turn — always present */
618
+ trace: TurnTrace;
619
+ }
620
+ export interface LLMProviderRequest {
621
+ systemPrompt: string;
622
+ history: Array<{
623
+ role: 'user' | 'assistant';
624
+ content: string;
625
+ }>;
626
+ message: string;
627
+ responseSchema?: Record<string, unknown>;
628
+ temperature?: number;
629
+ /** Multimodal attachments (e.g. images) */
630
+ attachments?: ChatAttachment[];
631
+ }
632
+ export interface TracedLLMRequest {
633
+ systemPrompt: string;
634
+ history: Array<{
635
+ role: 'user' | 'assistant';
636
+ content: string;
637
+ }>;
638
+ message: string;
639
+ responseSchema?: Record<string, unknown>;
640
+ attachments?: Array<{
641
+ type: ChatAttachment['type'];
642
+ mimeType: string;
643
+ dataSha256: string;
644
+ dataLength: number;
645
+ }>;
646
+ promptMode?: PromptMode;
647
+ promptOrigin?: PromptOrigin;
648
+ }
649
+ export interface LLMRequestFingerprint {
650
+ sha256: string;
651
+ systemPromptSha256?: string;
652
+ historySha256?: string;
653
+ messageSha256?: string;
654
+ responseSchemaSha256?: string;
655
+ historyCount?: number;
656
+ attachmentCount?: number;
657
+ }
658
+ export interface LLMProviderAttempt {
659
+ model: string;
660
+ status: 'success' | 'failed';
661
+ error?: string;
662
+ retryable?: boolean;
663
+ }
664
+ export interface LLMProviderResponse {
665
+ text: string;
666
+ /** Actual model that returned this response, when the provider exposes it. */
667
+ model?: string;
668
+ /** Requested primary model, when different from the provider name or useful for fallback traces. */
669
+ requestedModel?: string;
670
+ /** Fingerprint of the provider payload shared by every fallback attempt. */
671
+ requestFingerprint?: LLMRequestFingerprint;
672
+ /** Provider attempts made before a response or terminal failure. */
673
+ attempts?: LLMProviderAttempt[];
674
+ }
675
+ export interface LLMProvider {
676
+ name: string;
677
+ /**
678
+ * How assistant history should be transported back into the provider on
679
+ * future turns. Most providers consume plain text history. Providers that
680
+ * reconstruct native tool/function-call parts from assistant history can
681
+ * opt into compact JSON transport.
682
+ */
683
+ historyTransport?: 'text' | 'compact-function-calls';
684
+ chat(request: LLMProviderRequest): Promise<LLMProviderResponse>;
685
+ }
686
+ export interface ManagedChatInput {
687
+ message: string;
688
+ conversationId?: string | null;
689
+ context?: Record<string, unknown>;
690
+ /** Which persona is making this call (for trace correlation) */
691
+ personaId?: string;
692
+ /** Links traces across personas in one user interaction */
693
+ correlationId?: string;
694
+ timezone?: string;
695
+ promptNow?: Date | string;
696
+ directives?: string | null;
697
+ extraSystemSections?: string[];
698
+ knowledgeDocuments?: KnowledgeDocument[];
699
+ promptMode?: PromptMode;
700
+ promptOrigin?: PromptOrigin;
701
+ promptScaffold?: PromptScaffoldConfig;
702
+ userIdentity?: string;
703
+ trigger?: string;
704
+ metadata?: Record<string, unknown>;
705
+ /** Locale code (e.g. 'he', 'en') */
706
+ locale?: string;
707
+ /** Multimodal attachments (e.g. images) */
708
+ attachments?: ChatAttachment[];
709
+ /** Pre-commit CRUD validation. SDK validates proposals and retries once on failure. */
710
+ crudValidation?: CrudValidationFn;
711
+ /** Max CRUD validation retries (default: 1) */
712
+ crudValidationRetries?: number;
713
+ /** Prompt-facing action/entity contract verbosity. */
714
+ contractStyle?: PromptContractStyle;
715
+ /**
716
+ * Optional app-owned CRUD commit boundary.
717
+ * When provided, managed mode executes non-SDK CRUD actions before saving the
718
+ * assistant message, then stores compact factual outcomes in future history.
719
+ */
720
+ domainCrud?: ManagedDomainCrudConfig;
721
+ }
722
+ export interface ManagedDomainCrudEntityHandler {
723
+ create?: (id: string, params: Record<string, unknown>) => Promise<ManagedDomainCrudCommitResult>;
724
+ update?: (id: string, params: Record<string, unknown>) => Promise<ManagedDomainCrudCommitResult>;
725
+ delete?: (id: string) => Promise<ManagedDomainCrudCommitResult>;
726
+ }
727
+ export interface ManagedDomainCrudCommitResult {
728
+ success: boolean;
729
+ error?: string;
730
+ data?: unknown;
731
+ }
732
+ export interface ManagedDomainCrudSummaryInput {
733
+ actions: CrudAction[];
734
+ results: ManagedDomainCrudCommitResult[];
735
+ }
736
+ export interface ManagedDomainCrudConfig {
737
+ handlers: Record<string, ManagedDomainCrudEntityHandler>;
738
+ /** Optional app-owned normalization before commit, such as deduping or ID repointing. */
739
+ prepare?: (actions: CrudAction[]) => CrudAction[] | Promise<CrudAction[]>;
740
+ summarize?: (input: ManagedDomainCrudSummaryInput) => string[] | Promise<string[]>;
741
+ }
742
+ export interface PromptedTurnPromptInput {
743
+ config: PersonaConfig;
744
+ input: Pick<ChatInput, 'timezone' | 'promptNow' | 'userIdentity' | 'locale' | 'memories' | 'knowledgeDocuments' | 'craftMemories' | 'context' | 'directives' | 'extraSystemSections' | 'tailSystemSections' | 'promptMode' | 'promptScaffold' | 'workingSet' | 'contractStyle'>;
745
+ /** Classifies app-initiated turns that should still read like a conversation */
746
+ turnKind?: PromptedTurnKind;
747
+ /** What the app is trying to accomplish with this initiated turn */
748
+ intent: string;
749
+ /** Optional short label for debugging and prompt clarity */
750
+ label?: string;
751
+ /** App-provided prompted-turn guidelines */
752
+ guidelines?: string;
753
+ /** Recent conversation history for continuity */
754
+ history?: Array<{
755
+ role: 'user' | 'assistant';
756
+ content: string;
757
+ }>;
758
+ }
759
+ export interface RetrospectPromptInput {
760
+ config: PersonaConfig;
761
+ input: Pick<ChatInput, 'timezone' | 'promptNow' | 'userIdentity' | 'locale' | 'memories' | 'knowledgeDocuments' | 'craftMemories' | 'context' | 'directives' | 'extraSystemSections' | 'tailSystemSections' | 'promptMode' | 'promptScaffold' | 'workingSet' | 'contractStyle'>;
762
+ /** Optional app-provided retrospective guidelines */
763
+ guidelines?: string;
764
+ /** Recent conversation history for pattern inference */
765
+ history?: Array<{
766
+ role: 'user' | 'assistant';
767
+ content: string;
768
+ }>;
769
+ }
770
+ export interface PromptedTurnInput {
771
+ intent: string;
772
+ label?: string;
773
+ timezone?: string;
774
+ promptNow?: Date | string;
775
+ userIdentity?: string;
776
+ locale?: string;
777
+ memories?: Memory[];
778
+ knowledgeDocuments?: KnowledgeDocument[];
779
+ craftMemories?: Memory[];
780
+ context?: Record<string, unknown>;
781
+ directives?: string | null;
782
+ extraSystemSections?: string[];
783
+ tailSystemSections?: string[];
784
+ turnKind?: PromptedTurnKind;
785
+ promptMode?: PromptMode;
786
+ promptScaffold?: PromptScaffoldConfig;
787
+ contractStyle?: PromptContractStyle;
788
+ guidelines?: string;
789
+ history?: Array<{
790
+ role: 'user' | 'assistant';
791
+ content: string;
792
+ }>;
793
+ workingSet?: WorkingSet | null;
794
+ /** Pre-commit CRUD validation. If provided, the SDK validates proposals and retries once on failure. */
795
+ crudValidation?: CrudValidationFn;
796
+ /** Max CRUD validation retries (default: 1) */
797
+ crudValidationRetries?: number;
798
+ }
799
+ export interface GreetingInput extends Omit<PromptedTurnInput, 'intent' | 'label' | 'directives'> {
800
+ }
801
+ export interface RetrospectInput {
802
+ timezone?: string;
803
+ promptNow?: Date | string;
804
+ userIdentity?: string;
805
+ locale?: string;
806
+ memories?: Memory[];
807
+ knowledgeDocuments?: KnowledgeDocument[];
808
+ craftMemories?: Memory[];
809
+ context?: Record<string, unknown>;
810
+ directives?: string | null;
811
+ extraSystemSections?: string[];
812
+ tailSystemSections?: string[];
813
+ promptMode?: PromptMode;
814
+ promptScaffold?: PromptScaffoldConfig;
815
+ contractStyle?: PromptContractStyle;
816
+ guidelines?: string;
817
+ history?: Array<{
818
+ role: 'user' | 'assistant';
819
+ content: string;
820
+ }>;
821
+ workingSet?: WorkingSet | null;
822
+ }
823
+ export interface ManagedPromptedTurnInput {
824
+ intent: string;
825
+ label?: string;
826
+ conversationId?: string | null;
827
+ context?: Record<string, unknown>;
828
+ /** Which persona is making this call (for trace correlation) */
829
+ personaId?: string;
830
+ /** Links traces across personas in one user interaction */
831
+ correlationId?: string;
832
+ timezone?: string;
833
+ promptNow?: Date | string;
834
+ userIdentity?: string;
835
+ locale?: string;
836
+ knowledgeDocuments?: KnowledgeDocument[];
837
+ directives?: string | null;
838
+ extraSystemSections?: string[];
839
+ turnKind?: PromptedTurnKind;
840
+ promptMode?: PromptMode;
841
+ contractStyle?: PromptContractStyle;
842
+ promptScaffold?: PromptScaffoldConfig;
843
+ guidelines?: string;
844
+ history?: Array<{
845
+ role: 'user' | 'assistant';
846
+ content: string;
847
+ }>;
848
+ trigger?: string;
849
+ metadata?: Record<string, unknown>;
850
+ /** Pre-commit CRUD validation. SDK validates proposals and retries once on failure. */
851
+ crudValidation?: CrudValidationFn;
852
+ /** Max CRUD validation retries (default: 1) */
853
+ crudValidationRetries?: number;
854
+ /**
855
+ * Optional app-owned CRUD commit boundary.
856
+ * When provided, managed mode executes non-SDK CRUD actions before saving the
857
+ * assistant message, then stores compact factual outcomes in future history.
858
+ */
859
+ domainCrud?: ManagedDomainCrudConfig;
860
+ }
861
+ export interface ManagedGreetingInput extends Omit<ManagedPromptedTurnInput, 'intent' | 'label' | 'directives'> {
862
+ }
863
+ export interface ManagedRetrospectInput {
864
+ conversationId?: string | null;
865
+ context?: Record<string, unknown>;
866
+ timezone?: string;
867
+ promptNow?: Date | string;
868
+ userIdentity?: string;
869
+ locale?: string;
870
+ knowledgeDocuments?: KnowledgeDocument[];
871
+ directives?: string | null;
872
+ extraSystemSections?: string[];
873
+ promptMode?: PromptMode;
874
+ promptScaffold?: PromptScaffoldConfig;
875
+ guidelines?: string;
876
+ history?: Array<{
877
+ role: 'user' | 'assistant';
878
+ content: string;
879
+ }>;
880
+ }
881
+ export interface StorageAdapter {
882
+ getActiveConversation(): Promise<Conversation | null>;
883
+ createConversation(trigger: string, metadata?: Record<string, unknown>): Promise<string>;
884
+ endConversation(id: string): Promise<void>;
885
+ getMessages(conversationId: string, limit: number): Promise<Message[]>;
886
+ saveMessage(conversationId: string, msg: Omit<Message, 'createdAt'>): Promise<void>;
887
+ /**
888
+ * Load a candidate set of memories for prompt injection.
889
+ * `budget` is a soft loading budget, not the final prompt crop. Adapters should
890
+ * avoid doing the last-mile trim too aggressively because Archetype applies the
891
+ * final salience-aware selection itself.
892
+ */
893
+ loadMemories(options: {
894
+ budget: number;
895
+ pinnedFirst: boolean;
896
+ }): Promise<Memory[]>;
897
+ saveMemory(memory: Omit<Memory, 'id'>): Promise<string>;
898
+ updateMemory(id: string, updates: Partial<Memory>): Promise<void>;
899
+ deleteMemory(id: string): Promise<void>;
900
+ loadWorkingSet?(conversationId: string): Promise<WorkingSet | null>;
901
+ saveWorkingSet?(conversationId: string, workingSet: WorkingSet): Promise<void>;
902
+ clearWorkingSet?(conversationId: string): Promise<void>;
903
+ /** Load craft memories (persona-scoped professional growth). Same soft-budget guidance as loadMemories. */
904
+ loadCraftMemories?(options: {
905
+ budget: number;
906
+ }): Promise<Memory[]>;
907
+ /** Save a craft memory */
908
+ saveCraftMemory?(memory: Omit<Memory, 'id'>): Promise<string>;
909
+ /** Update a craft memory */
910
+ updateCraftMemory?(id: string, updates: Partial<Memory>): Promise<void>;
911
+ /** Delete a craft memory */
912
+ deleteCraftMemory?(id: string): Promise<void>;
913
+ /** Save a turn trace for debugging */
914
+ saveTrace?(conversationId: string, trace: TurnTrace): Promise<void>;
915
+ /** Load turn traces for a conversation */
916
+ getTraces?(conversationId: string, options?: {
917
+ limit?: number;
918
+ }): Promise<TurnTrace[]>;
919
+ }
920
+ //# sourceMappingURL=types.d.ts.map