@inf-minds/mindkit 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/dist/extensions/index.d.ts +2 -0
  2. package/dist/extensions/index.d.ts.map +1 -0
  3. package/dist/extensions/index.js +6 -0
  4. package/dist/extensions/index.js.map +1 -0
  5. package/dist/index.d.ts +5 -0
  6. package/dist/index.d.ts.map +1 -0
  7. package/dist/index.js +9 -0
  8. package/dist/index.js.map +1 -0
  9. package/dist/mind.d.ts +15 -0
  10. package/dist/mind.d.ts.map +1 -0
  11. package/dist/mind.js +274 -0
  12. package/dist/mind.js.map +1 -0
  13. package/dist/providers/anthropic.d.ts +9 -0
  14. package/dist/providers/anthropic.d.ts.map +1 -0
  15. package/dist/providers/anthropic.js +20 -0
  16. package/dist/providers/anthropic.js.map +1 -0
  17. package/dist/providers/index.d.ts +4 -0
  18. package/dist/providers/index.d.ts.map +1 -0
  19. package/dist/providers/index.js +6 -0
  20. package/dist/providers/index.js.map +1 -0
  21. package/dist/providers/openai.d.ts +9 -0
  22. package/dist/providers/openai.d.ts.map +1 -0
  23. package/dist/providers/openai.js +20 -0
  24. package/dist/providers/openai.js.map +1 -0
  25. package/dist/providers/select.d.ts +17 -0
  26. package/dist/providers/select.d.ts.map +1 -0
  27. package/dist/providers/select.js +44 -0
  28. package/dist/providers/select.js.map +1 -0
  29. package/dist/types.d.ts +156 -0
  30. package/dist/types.d.ts.map +1 -0
  31. package/dist/types.js +4 -0
  32. package/dist/types.js.map +1 -0
  33. package/package.json +42 -0
  34. package/src/extensions/index.ts +7 -0
  35. package/src/index.ts +32 -0
  36. package/src/mind.ts +348 -0
  37. package/src/providers/anthropic.ts +22 -0
  38. package/src/providers/index.ts +6 -0
  39. package/src/providers/openai.ts +22 -0
  40. package/src/providers/select.ts +56 -0
  41. package/src/types.ts +147 -0
@@ -0,0 +1,56 @@
1
+ // ABOUTME: Model selection logic for mindkit
2
+ // ABOUTME: Auto-detects provider from model ID and creates appropriate model instance
3
+
4
+ import type { LanguageModel } from 'ai';
5
+ import { createAnthropicModel } from './anthropic.js';
6
+ import { createOpenAIModel } from './openai.js';
7
+
8
+ export type ModelProvider = 'anthropic' | 'openai';
9
+
10
+ /**
11
+ * Detect provider from model ID
12
+ * @param modelId - Model identifier
13
+ * @returns Detected provider
14
+ */
15
+ export function detectProvider(modelId: string): ModelProvider {
16
+ // Anthropic models
17
+ if (
18
+ modelId.includes('claude') ||
19
+ modelId.startsWith('claude-')
20
+ ) {
21
+ return 'anthropic';
22
+ }
23
+
24
+ // OpenAI models
25
+ if (
26
+ modelId.includes('gpt') ||
27
+ modelId.startsWith('gpt-') ||
28
+ modelId.startsWith('o1') ||
29
+ modelId.startsWith('o3')
30
+ ) {
31
+ return 'openai';
32
+ }
33
+
34
+ // Default to OpenAI for unknown models
35
+ return 'openai';
36
+ }
37
+
38
+ /**
39
+ * Select and create model instance based on model ID and optional provider override
40
+ * @param modelId - Model identifier
41
+ * @param provider - Optional provider override
42
+ * @param apiKey - Optional API key (required for edge runtimes like Cloudflare Workers)
43
+ * @returns Model instance
44
+ */
45
+ export function selectModel(modelId: string, provider?: ModelProvider, apiKey?: string): LanguageModel {
46
+ const resolvedProvider = provider ?? detectProvider(modelId);
47
+
48
+ switch (resolvedProvider) {
49
+ case 'anthropic':
50
+ return createAnthropicModel(modelId, apiKey);
51
+ case 'openai':
52
+ return createOpenAIModel(modelId, apiKey);
53
+ default:
54
+ throw new Error(`Unknown provider: ${resolvedProvider}`);
55
+ }
56
+ }
package/src/types.ts ADDED
@@ -0,0 +1,147 @@
1
+ // ABOUTME: Core types for mindkit - Mind, MindConfig, MindExtension, MindEvent
2
+ // ABOUTME: Defines the interface for single mind runtime using Mastra
3
+
4
+ import type { ArtifactRef, VisibilityHints } from '@inf-minds/jobs';
5
+
6
+ /**
7
+ * Unique ID generator type
8
+ */
9
+ export type GenerateId = () => string;
10
+
11
+ /**
12
+ * Unsubscribe function returned by subscribe methods
13
+ */
14
+ export type Unsubscribe = () => void;
15
+
16
+ /**
17
+ * Token usage statistics from LLM calls
18
+ */
19
+ export interface TokenUsage {
20
+ promptTokens: number;
21
+ completionTokens: number;
22
+ totalTokens: number;
23
+ }
24
+
25
+ /**
26
+ * Tool definition for minds
27
+ */
28
+ export interface ToolDefinition {
29
+ name: string;
30
+ description: string;
31
+ parameters: Record<string, unknown>;
32
+ execute: (args: unknown) => Promise<unknown>;
33
+ }
34
+
35
+ /**
36
+ * Mind configuration
37
+ */
38
+ export interface MindConfig {
39
+ /** Model identifier (e.g., 'claude-sonnet-4-20250514', 'gpt-4o') */
40
+ model: string;
41
+ /** LLM provider - auto-detected from model if not specified */
42
+ provider?: 'anthropic' | 'openai';
43
+ /** API key for the provider (required for edge runtimes like Cloudflare Workers) */
44
+ apiKey?: string;
45
+ /** System prompt for the mind */
46
+ systemPrompt?: string;
47
+ /** Tools available to the mind */
48
+ tools?: ToolDefinition[];
49
+ /** Maximum tokens for completion */
50
+ maxTokens?: number;
51
+ /** Temperature for sampling */
52
+ temperature?: number;
53
+ /** Extensions to compose into the mind */
54
+ extensions?: MindExtension[];
55
+ }
56
+
57
+ /**
58
+ * Input to a mind execution
59
+ */
60
+ export interface MindInput {
61
+ /** The task or prompt for the mind */
62
+ task: string;
63
+ /** Additional context data */
64
+ context?: Record<string, unknown>;
65
+ /** Artifact references available to the mind */
66
+ artifacts?: ArtifactRef[];
67
+ /** Artifact paths to load */
68
+ artifactPaths?: string[];
69
+ }
70
+
71
+ /**
72
+ * Artifact with visibility hints from mind output
73
+ */
74
+ export interface ArtifactWithHints {
75
+ ref: ArtifactRef;
76
+ hints: VisibilityHints;
77
+ }
78
+
79
+ /**
80
+ * Output from a mind execution
81
+ */
82
+ export interface MindOutput {
83
+ /** The result from the mind */
84
+ result: unknown;
85
+ /** Artifacts created by the mind with visibility hints */
86
+ artifacts?: ArtifactWithHints[];
87
+ /** Token usage statistics */
88
+ usage?: TokenUsage;
89
+ }
90
+
91
+ /**
92
+ * Mind extension for composable functionality
93
+ */
94
+ export interface MindExtension {
95
+ /** Extension name */
96
+ name: string;
97
+ /** Additional system prompt content */
98
+ systemPromptAddition?: string;
99
+ /** Additional tools provided by the extension */
100
+ tools?: ToolDefinition[];
101
+ /** Preprocess input before execution */
102
+ preprocessInput?: (input: MindInput) => MindInput;
103
+ /** Postprocess output after execution */
104
+ postprocessOutput?: (output: MindOutput) => MindOutput;
105
+ }
106
+
107
+ /**
108
+ * Events emitted during mind execution
109
+ */
110
+ export type MindEvent =
111
+ | { type: 'started'; timestamp: Date }
112
+ | { type: 'thinking'; content: string }
113
+ | { type: 'tool_call'; tool: string; args: unknown }
114
+ | { type: 'tool_result'; tool: string; result: unknown }
115
+ | { type: 'text_delta'; delta: string }
116
+ | { type: 'artifact_created'; ref: ArtifactRef; hints: VisibilityHints }
117
+ | { type: 'progress'; percent: number; message?: string }
118
+ | { type: 'completed'; output: MindOutput }
119
+ | { type: 'failed'; error: string };
120
+
121
+ /**
122
+ * Mind runtime interface
123
+ */
124
+ export interface Mind {
125
+ /** Unique mind instance ID */
126
+ readonly id: string;
127
+ /** Mind configuration */
128
+ readonly config: MindConfig;
129
+ /**
130
+ * Execute the mind with the given input
131
+ * @param input - Task and context for execution
132
+ * @returns Mind output with result and artifacts
133
+ */
134
+ run(input: MindInput): Promise<MindOutput>;
135
+ /**
136
+ * Execute the mind with streaming events
137
+ * @param input - Task and context for execution
138
+ * @returns Async iterable of mind events
139
+ */
140
+ stream(input: MindInput): AsyncIterable<MindEvent>;
141
+ /**
142
+ * Subscribe to mind events during execution
143
+ * @param handler - Event handler function
144
+ * @returns Unsubscribe function
145
+ */
146
+ subscribe(handler: (event: MindEvent) => void): Unsubscribe;
147
+ }