@memberjunction/ai-agents 5.28.0 → 5.29.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 (55) hide show
  1. package/dist/AgentRunner.d.ts +39 -0
  2. package/dist/AgentRunner.d.ts.map +1 -1
  3. package/dist/AgentRunner.js +300 -5
  4. package/dist/AgentRunner.js.map +1 -1
  5. package/dist/ArtifactToolManager.d.ts +165 -0
  6. package/dist/ArtifactToolManager.d.ts.map +1 -0
  7. package/dist/ArtifactToolManager.js +534 -0
  8. package/dist/ArtifactToolManager.js.map +1 -0
  9. package/dist/agent-types/loop-agent-prompt-params.d.ts +14 -0
  10. package/dist/agent-types/loop-agent-prompt-params.d.ts.map +1 -1
  11. package/dist/agent-types/loop-agent-prompt-params.js +3 -1
  12. package/dist/agent-types/loop-agent-prompt-params.js.map +1 -1
  13. package/dist/agent-types/loop-agent-response-type.d.ts +9 -1
  14. package/dist/agent-types/loop-agent-response-type.d.ts.map +1 -1
  15. package/dist/agent-types/loop-agent-response-type.js.map +1 -1
  16. package/dist/agent-types/loop-agent-type.d.ts.map +1 -1
  17. package/dist/agent-types/loop-agent-type.js +3 -0
  18. package/dist/agent-types/loop-agent-type.js.map +1 -1
  19. package/dist/artifact-tools/DataSnapshotToolLibrary.d.ts +18 -0
  20. package/dist/artifact-tools/DataSnapshotToolLibrary.d.ts.map +1 -0
  21. package/dist/artifact-tools/DataSnapshotToolLibrary.js +365 -0
  22. package/dist/artifact-tools/DataSnapshotToolLibrary.js.map +1 -0
  23. package/dist/artifact-tools/DocxToolLibrary.d.ts +15 -0
  24. package/dist/artifact-tools/DocxToolLibrary.d.ts.map +1 -0
  25. package/dist/artifact-tools/DocxToolLibrary.js +160 -0
  26. package/dist/artifact-tools/DocxToolLibrary.js.map +1 -0
  27. package/dist/artifact-tools/ExcelToolLibrary.d.ts +16 -0
  28. package/dist/artifact-tools/ExcelToolLibrary.d.ts.map +1 -0
  29. package/dist/artifact-tools/ExcelToolLibrary.js +300 -0
  30. package/dist/artifact-tools/ExcelToolLibrary.js.map +1 -0
  31. package/dist/artifact-tools/JSONToolLibrary.d.ts +18 -0
  32. package/dist/artifact-tools/JSONToolLibrary.d.ts.map +1 -0
  33. package/dist/artifact-tools/JSONToolLibrary.js +178 -0
  34. package/dist/artifact-tools/JSONToolLibrary.js.map +1 -0
  35. package/dist/artifact-tools/PDFToolLibrary.d.ts +14 -0
  36. package/dist/artifact-tools/PDFToolLibrary.d.ts.map +1 -0
  37. package/dist/artifact-tools/PDFToolLibrary.js +172 -0
  38. package/dist/artifact-tools/PDFToolLibrary.js.map +1 -0
  39. package/dist/artifact-tools/TextToolLibrary.d.ts +12 -0
  40. package/dist/artifact-tools/TextToolLibrary.d.ts.map +1 -0
  41. package/dist/artifact-tools/TextToolLibrary.js +82 -0
  42. package/dist/artifact-tools/TextToolLibrary.js.map +1 -0
  43. package/dist/base-agent.d.ts +5 -0
  44. package/dist/base-agent.d.ts.map +1 -1
  45. package/dist/base-agent.js +87 -6
  46. package/dist/base-agent.js.map +1 -1
  47. package/dist/file-input-resolver.d.ts +2 -0
  48. package/dist/file-input-resolver.d.ts.map +1 -0
  49. package/dist/file-input-resolver.js +4 -0
  50. package/dist/file-input-resolver.js.map +1 -0
  51. package/dist/index.d.ts +9 -1
  52. package/dist/index.d.ts.map +1 -1
  53. package/dist/index.js +9 -1
  54. package/dist/index.js.map +1 -1
  55. package/package.json +18 -15
@@ -0,0 +1,165 @@
1
+ import { NativeFileInput } from '@memberjunction/ai-core-plus';
2
+ /**
3
+ * An input artifact provided to an agent run.
4
+ */
5
+ export interface InputArtifact {
6
+ name: string;
7
+ typeName: string;
8
+ content: string | Buffer;
9
+ /** MIME type of the artifact content (e.g., 'application/pdf').
10
+ * Populated for file-backed artifacts from ArtifactVersion.MimeType. */
11
+ mimeType?: string;
12
+ /** Optional: class name from ArtifactType.ToolLibraryClass metadata.
13
+ * When set, used for plugin-based resolution via ClassFactory. */
14
+ toolLibraryClass?: string;
15
+ }
16
+ /**
17
+ * A single artifact tool invocation requested by the LLM.
18
+ */
19
+ export interface ArtifactToolCall {
20
+ /** Alpha-sequence artifact ID assigned at run start (A, B, ... Z, AA, AB, etc.) */
21
+ artifactId: string;
22
+ /** Tool name from the documented tool list */
23
+ tool: string;
24
+ /** Tool-specific input parameters */
25
+ input: Record<string, unknown>;
26
+ }
27
+ export interface ArtifactToolSnapshot {
28
+ artifacts: Array<{
29
+ alphaId: string;
30
+ name: string;
31
+ typeName: string;
32
+ }>;
33
+ resultCount: number;
34
+ }
35
+ /**
36
+ * A single tool invocation, projected from the internal result store.
37
+ * Used for audit / training-data / debugging.
38
+ */
39
+ export interface ArtifactAccessLogEntry {
40
+ artifactId: string;
41
+ tool: string;
42
+ input: Record<string, unknown>;
43
+ success: boolean;
44
+ errorMessage?: string;
45
+ timestamp: Date;
46
+ durationMs: number;
47
+ }
48
+ /**
49
+ * Manages artifact tools for a single agent run.
50
+ *
51
+ * Follows the ScratchpadManager pattern:
52
+ * - Instantiated once per run
53
+ * - Holds references to input artifacts with alpha IDs
54
+ * - Generates manifest + tool documentation for prompt injection
55
+ * - Executes tool calls and stores results for next turn
56
+ * - Serializable for persistence
57
+ */
58
+ export declare class ArtifactToolManager {
59
+ private artifacts;
60
+ private toolResults;
61
+ private nextAlphaIndex;
62
+ /** Initialize with input artifacts, assigning alpha IDs */
63
+ Initialize(inputArtifacts: InputArtifact[]): void;
64
+ /** Register a mid-run artifact and return its alpha ID */
65
+ RegisterArtifact(artifact: InputArtifact): string;
66
+ /** Reset all state */
67
+ Clear(): void;
68
+ /** Whether any artifacts are available */
69
+ HasArtifacts(): boolean;
70
+ /**
71
+ * Returns artifact content formatted as NativeFileInput candidates for the
72
+ * AIPromptRunner. Only artifacts with a known MIME type and string/Buffer
73
+ * content are included. The runner will check each against the driver's
74
+ * FileCapabilities before actually attaching them.
75
+ *
76
+ * For each candidate, eagerly extracts text content so the Prompts package
77
+ * can fall back to a plain-text injection when the driver doesn't support
78
+ * native file input (e.g., Cerebras, older OpenAI-compat providers).
79
+ */
80
+ GetNativeFileInputCandidates(): Promise<NativeFileInput[]>;
81
+ /**
82
+ * Best-effort text extraction for fallback when the driver doesn't support
83
+ * native file input. Returns null if extraction fails or isn't applicable
84
+ * (e.g., images, audio).
85
+ */
86
+ private extractTextFallback;
87
+ /** Extract all text from a PDF buffer using pdfjs-dist. Returns null on failure. */
88
+ private extractPdfText;
89
+ /** Markdown manifest: artifact IDs, names, types */
90
+ ToManifestString(): string;
91
+ /** Markdown tool documentation grouped by artifact type */
92
+ GetToolDocumentation(): string;
93
+ /**
94
+ * Max characters for the tool results section injected into the prompt.
95
+ * Prevents context overflow when tool results contain large datasets.
96
+ * Results are truncated from oldest first, with a summary of what was dropped.
97
+ */
98
+ private static readonly MAX_RESULTS_CHARS;
99
+ /**
100
+ * Max characters for a single tool result's data section.
101
+ * Individual results that exceed this are truncated with a note,
102
+ * preventing one huge result from consuming the entire budget.
103
+ */
104
+ private static readonly MAX_SINGLE_RESULT_CHARS;
105
+ /** Markdown results from previous turns */
106
+ GetPendingResults(): string;
107
+ /** One-line summary for compact contexts */
108
+ GetSummary(): string;
109
+ /** Execute tool calls from LLM response */
110
+ ExecuteToolCalls(calls: ArtifactToolCall[]): Promise<void>;
111
+ /** Snapshot for persistence */
112
+ ToJSON(): ArtifactToolSnapshot;
113
+ /**
114
+ * Access log for this run — one entry per tool invocation, in call order.
115
+ * Useful for audit trails, training data capture, and debugging.
116
+ * Projected from the internal result store (no parallel state).
117
+ */
118
+ GetAccessLog(): ArtifactAccessLogEntry[];
119
+ /**
120
+ * Determines whether artifact content should be externalized to MJStorage
121
+ * instead of being stored inline.
122
+ */
123
+ static ShouldExternalizeContent(contentLength: number, options?: {
124
+ maxInlineChars?: number;
125
+ }): {
126
+ shouldExternalize: boolean;
127
+ reason: string;
128
+ };
129
+ /**
130
+ * Builds a truncated inline preview of a tables-based content JSON by keeping
131
+ * only the first `maxRowsPerTable` rows per table and attaching truncation metadata.
132
+ */
133
+ static BuildInlinePreview(contentJson: string, maxRowsPerTable?: number): string;
134
+ /** Generate next alpha-sequence ID: A, B, ... Z, AA, AB, ... */
135
+ private NextAlphaId;
136
+ /**
137
+ * Resolve a tool library for an artifact type, walking the ParentID chain
138
+ * of `MJ: Artifact Types` to collect libraries from the leaf type and all
139
+ * ancestors. Child libraries override parent libraries for same-named tools.
140
+ *
141
+ * Resolution order:
142
+ * 1. If the metadata engine is loaded, walk `typeName → parent → ...` via
143
+ * `ArtifactMetadataEngine`, instantiating each level's `ToolLibraryClass`
144
+ * via ClassFactory. Returns a CompositeArtifactToolLibrary.
145
+ * 2. If the engine isn't loaded or the type isn't found, resolve the single
146
+ * leaf library using the `toolLibraryClass` hint plus name-based fallback.
147
+ *
148
+ * The engine is expected to be configured by AgentRunner before Initialize
149
+ * is called, so path (1) is the normal case.
150
+ */
151
+ private ResolveLibrary;
152
+ /**
153
+ * Walk the ParentID chain for `typeName` in ArtifactMetadataEngine,
154
+ * instantiating each level's ToolLibraryClass via ClassFactory.
155
+ * Returns the chain leaf-first. Levels without a ToolLibraryClass are
156
+ * skipped. Returns [] if the engine isn't loaded or the type isn't found.
157
+ */
158
+ private ResolveLibraryChain;
159
+ /**
160
+ * Single-library fallback when the metadata engine isn't available.
161
+ * Uses the provided `toolLibraryClass` hint first, then name-based heuristics.
162
+ */
163
+ private ResolveLeafLibrary;
164
+ }
165
+ //# sourceMappingURL=ArtifactToolManager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ArtifactToolManager.d.ts","sourceRoot":"","sources":["../src/ArtifactToolManager.ts"],"names":[],"mappings":"AAEA,OAAO,EAAuE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAKpI;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC;IACzB;6EACyE;IACzE,QA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