@mohanscodex/spectra-ai 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.
- package/README.md +189 -0
- package/dist/__tests__/e2e.test.d.ts +2 -0
- package/dist/__tests__/e2e.test.d.ts.map +1 -0
- package/dist/__tests__/e2e.test.js +364 -0
- package/dist/__tests__/e2e.test.js.map +1 -0
- package/dist/__tests__/event-stream.test.d.ts +2 -0
- package/dist/__tests__/event-stream.test.d.ts.map +1 -0
- package/dist/__tests__/event-stream.test.js +87 -0
- package/dist/__tests__/event-stream.test.js.map +1 -0
- package/dist/__tests__/provider.test.d.ts +2 -0
- package/dist/__tests__/provider.test.d.ts.map +1 -0
- package/dist/__tests__/provider.test.js +40 -0
- package/dist/__tests__/provider.test.js.map +1 -0
- package/dist/event-stream.d.ts +19 -0
- package/dist/event-stream.d.ts.map +1 -0
- package/dist/event-stream.js +74 -0
- package/dist/event-stream.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/models.d.ts +6 -0
- package/dist/models.d.ts.map +1 -0
- package/dist/models.js +16480 -0
- package/dist/models.js.map +1 -0
- package/dist/providers/anthropic.d.ts +8 -0
- package/dist/providers/anthropic.d.ts.map +1 -0
- package/dist/providers/anthropic.js +279 -0
- package/dist/providers/anthropic.js.map +1 -0
- package/dist/providers/groq.d.ts +16 -0
- package/dist/providers/groq.d.ts.map +1 -0
- package/dist/providers/groq.js +196 -0
- package/dist/providers/groq.js.map +1 -0
- package/dist/providers/openai-completions.d.ts +17 -0
- package/dist/providers/openai-completions.d.ts.map +1 -0
- package/dist/providers/openai-completions.js +319 -0
- package/dist/providers/openai-completions.js.map +1 -0
- package/dist/providers/openai-responses.d.ts +12 -0
- package/dist/providers/openai-responses.d.ts.map +1 -0
- package/dist/providers/openai-responses.js +335 -0
- package/dist/providers/openai-responses.js.map +1 -0
- package/dist/providers/openrouter.d.ts +12 -0
- package/dist/providers/openrouter.d.ts.map +1 -0
- package/dist/providers/openrouter.js +42 -0
- package/dist/providers/openrouter.js.map +1 -0
- package/dist/providers/register-builtins.d.ts +2 -0
- package/dist/providers/register-builtins.d.ts.map +1 -0
- package/dist/providers/register-builtins.js +41 -0
- package/dist/providers/register-builtins.js.map +1 -0
- package/dist/providers/shared.d.ts +3 -0
- package/dist/providers/shared.d.ts.map +1 -0
- package/dist/providers/shared.js +12 -0
- package/dist/providers/shared.js.map +1 -0
- package/dist/registry.d.ts +19 -0
- package/dist/registry.d.ts.map +1 -0
- package/dist/registry.js +28 -0
- package/dist/registry.js.map +1 -0
- package/dist/types.d.ts +164 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +33 -0
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
export interface TextContent {
|
|
2
|
+
type: "text";
|
|
3
|
+
text: string;
|
|
4
|
+
}
|
|
5
|
+
export interface ThinkingContent {
|
|
6
|
+
type: "thinking";
|
|
7
|
+
thinking: string;
|
|
8
|
+
thinkingSignature?: string;
|
|
9
|
+
redacted?: boolean;
|
|
10
|
+
}
|
|
11
|
+
export interface ImageContent {
|
|
12
|
+
type: "image";
|
|
13
|
+
data: string;
|
|
14
|
+
mimeType: string;
|
|
15
|
+
}
|
|
16
|
+
export interface ToolCall {
|
|
17
|
+
type: "toolCall";
|
|
18
|
+
id: string;
|
|
19
|
+
name: string;
|
|
20
|
+
arguments: Record<string, unknown>;
|
|
21
|
+
thinkingSignature?: string;
|
|
22
|
+
}
|
|
23
|
+
export type StopReason = "stop" | "length" | "toolUse" | "error" | "aborted";
|
|
24
|
+
export interface Usage {
|
|
25
|
+
input: number;
|
|
26
|
+
output: number;
|
|
27
|
+
cacheRead: number;
|
|
28
|
+
cacheWrite: number;
|
|
29
|
+
totalTokens: number;
|
|
30
|
+
cost?: {
|
|
31
|
+
input: number;
|
|
32
|
+
output: number;
|
|
33
|
+
cacheRead: number;
|
|
34
|
+
cacheWrite: number;
|
|
35
|
+
total: number;
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
export interface UserMessage {
|
|
39
|
+
role: "user";
|
|
40
|
+
content: string | (TextContent | ImageContent)[];
|
|
41
|
+
timestamp: number;
|
|
42
|
+
/** Arbitrary metadata for app/ui use. Ignored by LLM context. */
|
|
43
|
+
metadata?: Record<string, unknown>;
|
|
44
|
+
}
|
|
45
|
+
export interface AssistantMessage {
|
|
46
|
+
role: "assistant";
|
|
47
|
+
content: (TextContent | ThinkingContent | ToolCall)[];
|
|
48
|
+
provider: string;
|
|
49
|
+
model: string;
|
|
50
|
+
responseId?: string;
|
|
51
|
+
usage: Usage;
|
|
52
|
+
stopReason: StopReason;
|
|
53
|
+
errorMessage?: string;
|
|
54
|
+
timestamp: number;
|
|
55
|
+
/** Arbitrary metadata for app/ui use. Ignored by LLM context. */
|
|
56
|
+
metadata?: Record<string, unknown>;
|
|
57
|
+
}
|
|
58
|
+
export interface ToolResultMessage<TDetails = unknown> {
|
|
59
|
+
role: "toolResult";
|
|
60
|
+
toolCallId: string;
|
|
61
|
+
toolName: string;
|
|
62
|
+
content: (TextContent | ImageContent)[];
|
|
63
|
+
/** Typed tool-specific metadata (e.g. diff, truncation info). Ignored by LLM context. */
|
|
64
|
+
details?: TDetails;
|
|
65
|
+
isError: boolean;
|
|
66
|
+
timestamp: number;
|
|
67
|
+
/** Arbitrary metadata for app/ui use. Ignored by LLM context. */
|
|
68
|
+
metadata?: Record<string, unknown>;
|
|
69
|
+
provenance?: {
|
|
70
|
+
blockedBy?: string;
|
|
71
|
+
blockReason?: string;
|
|
72
|
+
transformedBy?: string;
|
|
73
|
+
retryCount?: number;
|
|
74
|
+
hookDetails?: Record<string, unknown>;
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
export type Message = UserMessage | AssistantMessage | ToolResultMessage;
|
|
78
|
+
export interface Tool {
|
|
79
|
+
name: string;
|
|
80
|
+
description: string;
|
|
81
|
+
parameters: {
|
|
82
|
+
type?: string;
|
|
83
|
+
properties?: Record<string, unknown>;
|
|
84
|
+
required?: string[];
|
|
85
|
+
[key: string]: unknown;
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
export interface Context {
|
|
89
|
+
systemPrompt?: string;
|
|
90
|
+
messages: Message[];
|
|
91
|
+
tools?: Tool[];
|
|
92
|
+
}
|
|
93
|
+
export type AssistantMessageEvent = {
|
|
94
|
+
type: "start";
|
|
95
|
+
partial: AssistantMessage;
|
|
96
|
+
} | {
|
|
97
|
+
type: "text_start";
|
|
98
|
+
contentIndex: number;
|
|
99
|
+
partial: AssistantMessage;
|
|
100
|
+
} | {
|
|
101
|
+
type: "text_delta";
|
|
102
|
+
contentIndex: number;
|
|
103
|
+
delta: string;
|
|
104
|
+
partial: AssistantMessage;
|
|
105
|
+
} | {
|
|
106
|
+
type: "text_end";
|
|
107
|
+
contentIndex: number;
|
|
108
|
+
content: string;
|
|
109
|
+
partial: AssistantMessage;
|
|
110
|
+
} | {
|
|
111
|
+
type: "thinking_start";
|
|
112
|
+
contentIndex: number;
|
|
113
|
+
partial: AssistantMessage;
|
|
114
|
+
} | {
|
|
115
|
+
type: "thinking_delta";
|
|
116
|
+
contentIndex: number;
|
|
117
|
+
delta: string;
|
|
118
|
+
partial: AssistantMessage;
|
|
119
|
+
} | {
|
|
120
|
+
type: "thinking_end";
|
|
121
|
+
contentIndex: number;
|
|
122
|
+
content: string;
|
|
123
|
+
partial: AssistantMessage;
|
|
124
|
+
} | {
|
|
125
|
+
type: "toolcall_start";
|
|
126
|
+
contentIndex: number;
|
|
127
|
+
partial: AssistantMessage;
|
|
128
|
+
} | {
|
|
129
|
+
type: "toolcall_delta";
|
|
130
|
+
contentIndex: number;
|
|
131
|
+
delta: string;
|
|
132
|
+
partial: AssistantMessage;
|
|
133
|
+
} | {
|
|
134
|
+
type: "toolcall_end";
|
|
135
|
+
contentIndex: number;
|
|
136
|
+
toolCall: ToolCall;
|
|
137
|
+
partial: AssistantMessage;
|
|
138
|
+
} | {
|
|
139
|
+
type: "done";
|
|
140
|
+
reason: StopReason;
|
|
141
|
+
message: AssistantMessage;
|
|
142
|
+
} | {
|
|
143
|
+
type: "error";
|
|
144
|
+
reason: StopReason;
|
|
145
|
+
error: AssistantMessage;
|
|
146
|
+
};
|
|
147
|
+
export interface StreamOptions {
|
|
148
|
+
signal?: AbortSignal;
|
|
149
|
+
apiKey?: string;
|
|
150
|
+
headers?: Record<string, string>;
|
|
151
|
+
maxTokens?: number;
|
|
152
|
+
temperature?: number;
|
|
153
|
+
}
|
|
154
|
+
export interface Model {
|
|
155
|
+
id: string;
|
|
156
|
+
name: string;
|
|
157
|
+
provider: string;
|
|
158
|
+
api: string;
|
|
159
|
+
baseUrl?: string;
|
|
160
|
+
reasoning?: boolean;
|
|
161
|
+
maxTokens?: number;
|
|
162
|
+
headers?: Record<string, string>;
|
|
163
|
+
}
|
|
164
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,UAAU,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,OAAO,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,UAAU,CAAC;IACjB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM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AAC,MAAM,EAAE,UAAU,CAAC;IAAC,OAAO,EAAE,gBAAgB,CAAA;CAAE,GAC/D;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,UAAU,CAAC;IAAC,KAAK,EAAE,gBAAgB,CAAA;CAAE,CAAC;AAEnE,MAAM,WAAW,aAAa;IAC5B,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,KAAK;IACpB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClC"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mohanscodex/spectra-ai",
|
|
3
|
+
"version": "0.4.0",
|
|
4
|
+
"description": "Spectra AI — LLM provider layer with streaming",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist"
|
|
16
|
+
],
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build": "npm run generate-models && tsc",
|
|
19
|
+
"dev": "tsc --watch",
|
|
20
|
+
"test": "vitest --run",
|
|
21
|
+
"lint": "tsc --noEmit",
|
|
22
|
+
"generate-models": "bun scripts/generate-models.ts"
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@anthropic-ai/sdk": "^0.32.0",
|
|
26
|
+
"openai": "^5.3.0"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"typescript": "^5.7.0",
|
|
30
|
+
"vitest": "^3.2.0"
|
|
31
|
+
},
|
|
32
|
+
"license": "MIT"
|
|
33
|
+
}
|