@astrive-ai/core 1.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.
- package/dist/context.d.ts +25 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +41 -0
- package/dist/context.js.map +1 -0
- package/dist/executor.d.ts +33 -0
- package/dist/executor.d.ts.map +1 -0
- package/dist/executor.js +99 -0
- package/dist/executor.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/middleware-pipeline.d.ts +7 -0
- package/dist/middleware-pipeline.d.ts.map +1 -0
- package/dist/middleware-pipeline.js +28 -0
- package/dist/middleware-pipeline.js.map +1 -0
- package/dist/retry.d.ts +15 -0
- package/dist/retry.d.ts.map +1 -0
- package/dist/retry.js +49 -0
- package/dist/retry.js.map +1 -0
- package/dist/structured-output.d.ts +13 -0
- package/dist/structured-output.d.ts.map +1 -0
- package/dist/structured-output.js +63 -0
- package/dist/structured-output.js.map +1 -0
- package/dist/tool-registry.d.ts +15 -0
- package/dist/tool-registry.d.ts.map +1 -0
- package/dist/tool-registry.js +46 -0
- package/dist/tool-registry.js.map +1 -0
- package/dist/utils.d.ts +16 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +70 -0
- package/dist/utils.js.map +1 -0
- package/dist/validator.d.ts +11 -0
- package/dist/validator.d.ts.map +1 -0
- package/dist/validator.js +85 -0
- package/dist/validator.js.map +1 -0
- package/package.json +26 -0
- package/src/context.ts +64 -0
- package/src/executor.ts +146 -0
- package/src/index.ts +8 -0
- package/src/middleware-pipeline.ts +33 -0
- package/src/retry.ts +62 -0
- package/src/structured-output.ts +80 -0
- package/src/tool-registry.ts +56 -0
- package/src/utils.ts +79 -0
- package/src/validator.ts +92 -0
- package/tsconfig.json +8 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export interface Message {
|
|
2
|
+
role: 'user' | 'assistant' | 'system' | 'tool';
|
|
3
|
+
content: string;
|
|
4
|
+
name?: string;
|
|
5
|
+
tool_calls?: any[];
|
|
6
|
+
tool_call_id?: string;
|
|
7
|
+
}
|
|
8
|
+
export interface ConversationContext {
|
|
9
|
+
id: string;
|
|
10
|
+
messages: Message[];
|
|
11
|
+
systemPrompt: string;
|
|
12
|
+
metadata: Record<string, unknown>;
|
|
13
|
+
createdAt: number;
|
|
14
|
+
updatedAt: number;
|
|
15
|
+
}
|
|
16
|
+
export declare class ContextManager {
|
|
17
|
+
private conversations;
|
|
18
|
+
createConversation(systemPrompt?: string): string;
|
|
19
|
+
addMessage(conversationId: string, message: Message): void;
|
|
20
|
+
getMessages(conversationId: string): Message[];
|
|
21
|
+
getConversation(conversationId: string): ConversationContext;
|
|
22
|
+
deleteConversation(conversationId: string): void;
|
|
23
|
+
clear(): void;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,OAAO;IACtB,IAAI,EAAE,MAAM,GAAG,WAAW,GAAG,QAAQ,GAAG,MAAM,CAAC;IAC/C,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,GAAG,EAAE,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,mBAAmB;IAClC,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,OAAO,EAAE,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,qBAAa,cAAc;IACzB,OAAO,CAAC,aAAa,CAA+C;IAE7D,kBAAkB,CAAC,YAAY,GAAE,MAAW,GAAG,MAAM;IAarD,UAAU,CAAC,cAAc,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,IAAI;IAS1D,WAAW,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,EAAE;IAI9C,eAAe,CAAC,cAAc,EAAE,MAAM,GAAG,mBAAmB;IAQ5D,kBAAkB,CAAC,cAAc,EAAE,MAAM,GAAG,IAAI;IAIhD,KAAK,IAAI,IAAI;CAGrB"}
|
package/dist/context.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import * as crypto from 'crypto';
|
|
2
|
+
export class ContextManager {
|
|
3
|
+
conversations = new Map();
|
|
4
|
+
createConversation(systemPrompt = '') {
|
|
5
|
+
const id = crypto.randomUUID();
|
|
6
|
+
this.conversations.set(id, {
|
|
7
|
+
id,
|
|
8
|
+
messages: [],
|
|
9
|
+
systemPrompt,
|
|
10
|
+
metadata: {},
|
|
11
|
+
createdAt: Date.now(),
|
|
12
|
+
updatedAt: Date.now()
|
|
13
|
+
});
|
|
14
|
+
return id;
|
|
15
|
+
}
|
|
16
|
+
addMessage(conversationId, message) {
|
|
17
|
+
const conv = this.conversations.get(conversationId);
|
|
18
|
+
if (!conv) {
|
|
19
|
+
throw new Error(`Conversation not found: ${conversationId}`);
|
|
20
|
+
}
|
|
21
|
+
conv.messages.push(message);
|
|
22
|
+
conv.updatedAt = Date.now();
|
|
23
|
+
}
|
|
24
|
+
getMessages(conversationId) {
|
|
25
|
+
return this.conversations.get(conversationId)?.messages || [];
|
|
26
|
+
}
|
|
27
|
+
getConversation(conversationId) {
|
|
28
|
+
const conv = this.conversations.get(conversationId);
|
|
29
|
+
if (!conv) {
|
|
30
|
+
throw new Error(`Conversation not found: ${conversationId}`);
|
|
31
|
+
}
|
|
32
|
+
return conv;
|
|
33
|
+
}
|
|
34
|
+
deleteConversation(conversationId) {
|
|
35
|
+
this.conversations.delete(conversationId);
|
|
36
|
+
}
|
|
37
|
+
clear() {
|
|
38
|
+
this.conversations.clear();
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AAmBjC,MAAM,OAAO,cAAc;IACjB,aAAa,GAAqC,IAAI,GAAG,EAAE,CAAC;IAE7D,kBAAkB,CAAC,eAAuB,EAAE;QACjD,MAAM,EAAE,GAAG,MAAM,CAAC,UAAU,EAAE,CAAC;QAC/B,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,EAAE,EAAE;YACzB,EAAE;YACF,QAAQ,EAAE,EAAE;YACZ,YAAY;YACZ,QAAQ,EAAE,EAAE;YACZ,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;YACrB,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;SACtB,CAAC,CAAC;QACH,OAAO,EAAE,CAAC;IACZ,CAAC;IAEM,UAAU,CAAC,cAAsB,EAAE,OAAgB;QACxD,MAAM,IAAI,GAAG,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;QACpD,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,MAAM,IAAI,KAAK,CAAC,2BAA2B,cAAc,EAAE,CAAC,CAAC;QAC/D,CAAC;QACD,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAC5B,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IAC9B,CAAC;IAEM,WAAW,CAAC,cAAsB;QACvC,OAAO,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,cAAc,CAAC,EAAE,QAAQ,IAAI,EAAE,CAAC;IAChE,CAAC;IAEM,eAAe,CAAC,cAAsB;QAC3C,MAAM,IAAI,GAAG,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;QACpD,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,MAAM,IAAI,KAAK,CAAC,2BAA2B,cAAc,EAAE,CAAC,CAAC;QAC/D,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAEM,kBAAkB,CAAC,cAAsB;QAC9C,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC;IAC5C,CAAC;IAEM,KAAK;QACV,IAAI,CAAC,aAAa,CAAC,KAAK,EAAE,CAAC;IAC7B,CAAC;CACF"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { ToolRegistry } from './tool-registry.js';
|
|
2
|
+
import { ILogger, IEventEmitter, ToolCall, ToolResult } from '@astrive-ai/types';
|
|
3
|
+
export interface ExecutorToolResult {
|
|
4
|
+
toolCallId: string;
|
|
5
|
+
result?: ToolResult;
|
|
6
|
+
error?: string;
|
|
7
|
+
status: 'success' | 'error';
|
|
8
|
+
}
|
|
9
|
+
export interface ExecutorContext {
|
|
10
|
+
[key: string]: any;
|
|
11
|
+
}
|
|
12
|
+
export interface ExecutionStep {
|
|
13
|
+
id: string;
|
|
14
|
+
toolCall: ToolCall;
|
|
15
|
+
dependencies?: string[];
|
|
16
|
+
status?: 'pending' | 'running' | 'completed' | 'failed';
|
|
17
|
+
result?: ExecutorToolResult;
|
|
18
|
+
}
|
|
19
|
+
export interface ExecutionPlan {
|
|
20
|
+
steps: ExecutionStep[];
|
|
21
|
+
}
|
|
22
|
+
export declare class ToolExecutor {
|
|
23
|
+
private registry;
|
|
24
|
+
private events;
|
|
25
|
+
private logger;
|
|
26
|
+
private validator;
|
|
27
|
+
private retryHandler;
|
|
28
|
+
constructor(registry: ToolRegistry, events: IEventEmitter, logger: ILogger);
|
|
29
|
+
execute(toolCall: ToolCall, context?: ExecutorContext): Promise<ExecutorToolResult>;
|
|
30
|
+
executeParallel(toolCalls: ToolCall[], context?: ExecutorContext): Promise<ExecutorToolResult[]>;
|
|
31
|
+
executePlan(plan: ExecutionPlan, context?: ExecutorContext): Promise<ExecutorToolResult[]>;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=executor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"executor.d.ts","sourceRoot":"","sources":["../src/executor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAGlD,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAEjF,MAAM,WAAW,kBAAkB;IACjC,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,UAAU,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,SAAS,GAAG,OAAO,CAAC;CAC7B;AAED,MAAM,WAAW,eAAe;IAC9B,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AAED,MAAM,WAAW,aAAa;IAC5B,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,QAAQ,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,MAAM,CAAC,EAAE,SAAS,GAAG,SAAS,GAAG,WAAW,GAAG,QAAQ,CAAC;IACxD,MAAM,CAAC,EAAE,kBAAkB,CAAC;CAC7B;AAED,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,aAAa,EAAE,CAAC;CACxB;AAED,qBAAa,YAAY;IACvB,OAAO,CAAC,QAAQ,CAAe;IAC/B,OAAO,CAAC,MAAM,CAAgB;IAC9B,OAAO,CAAC,MAAM,CAAU;IACxB,OAAO,CAAC,SAAS,CAAmB;IACpC,OAAO,CAAC,YAAY,CAAe;gBAEvB,QAAQ,EAAE,YAAY,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,OAAO;IAQ7D,OAAO,CAAC,QAAQ,EAAE,QAAQ,EAAE,OAAO,GAAE,eAAoB,GAAG,OAAO,CAAC,kBAAkB,CAAC;IA+CvF,eAAe,CAAC,SAAS,EAAE,QAAQ,EAAE,EAAE,OAAO,GAAE,eAAoB,GAAG,OAAO,CAAC,kBAAkB,EAAE,CAAC;IAKpG,WAAW,CAAC,IAAI,EAAE,aAAa,EAAE,OAAO,GAAE,eAAoB,GAAG,OAAO,CAAC,kBAAkB,EAAE,CAAC;CAkD5G"}
|
package/dist/executor.js
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { RequestValidator } from './validator.js';
|
|
2
|
+
import { RetryHandler } from './retry.js';
|
|
3
|
+
export class ToolExecutor {
|
|
4
|
+
registry;
|
|
5
|
+
events;
|
|
6
|
+
logger;
|
|
7
|
+
validator;
|
|
8
|
+
retryHandler;
|
|
9
|
+
constructor(registry, events, logger) {
|
|
10
|
+
this.registry = registry;
|
|
11
|
+
this.events = events;
|
|
12
|
+
this.logger = logger;
|
|
13
|
+
this.validator = new RequestValidator();
|
|
14
|
+
this.retryHandler = new RetryHandler();
|
|
15
|
+
}
|
|
16
|
+
async execute(toolCall, context = {}) {
|
|
17
|
+
await this.events.emit('tool:start', { toolCall });
|
|
18
|
+
this.logger.debug(`Starting tool: ${toolCall.name}`);
|
|
19
|
+
const tool = this.registry.get(toolCall.name);
|
|
20
|
+
if (!tool) {
|
|
21
|
+
const errorMsg = `Tool not found: ${toolCall.name}`;
|
|
22
|
+
this.logger.error(errorMsg);
|
|
23
|
+
await this.events.emit('tool:end', { toolCall, status: 'error', error: errorMsg });
|
|
24
|
+
return { toolCallId: toolCall.id, error: errorMsg, status: 'error' };
|
|
25
|
+
}
|
|
26
|
+
const validation = tool.validate(toolCall.arguments);
|
|
27
|
+
if (!validation.valid) {
|
|
28
|
+
const errorMsg = `Validation failed for tool ${toolCall.name}: ${validation.errors?.map(e => e.message).join(', ')}`;
|
|
29
|
+
this.logger.error(errorMsg);
|
|
30
|
+
await this.events.emit('tool:end', { toolCall, status: 'error', error: errorMsg });
|
|
31
|
+
return { toolCallId: toolCall.id, error: errorMsg, status: 'error' };
|
|
32
|
+
}
|
|
33
|
+
const controller = new AbortController();
|
|
34
|
+
const timeout = setTimeout(() => controller.abort(), 30000);
|
|
35
|
+
try {
|
|
36
|
+
const executeFn = async () => {
|
|
37
|
+
if (controller.signal.aborted)
|
|
38
|
+
throw new Error('Timeout');
|
|
39
|
+
return await tool.execute(toolCall.arguments, { ...context, signal: controller.signal });
|
|
40
|
+
};
|
|
41
|
+
const result = await this.retryHandler.execute(executeFn, {
|
|
42
|
+
maxRetries: 3,
|
|
43
|
+
baseDelay: 1000,
|
|
44
|
+
maxDelay: 10000,
|
|
45
|
+
backoffMultiplier: 2
|
|
46
|
+
});
|
|
47
|
+
clearTimeout(timeout);
|
|
48
|
+
await this.events.emit('tool:end', { toolCall, status: 'success', result });
|
|
49
|
+
return { toolCallId: toolCall.id, result, status: 'success' };
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
clearTimeout(timeout);
|
|
53
|
+
this.logger.error(`Error executing tool ${toolCall.name}:`, error);
|
|
54
|
+
await this.events.emit('tool:end', { toolCall, status: 'error', error: error.message });
|
|
55
|
+
return { toolCallId: toolCall.id, error: error.message, status: 'error' };
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
async executeParallel(toolCalls, context = {}) {
|
|
59
|
+
const promises = toolCalls.map(tc => this.execute(tc, context));
|
|
60
|
+
return await Promise.all(promises);
|
|
61
|
+
}
|
|
62
|
+
async executePlan(plan, context = {}) {
|
|
63
|
+
const results = [];
|
|
64
|
+
for (const step of plan.steps) {
|
|
65
|
+
step.status = 'pending';
|
|
66
|
+
}
|
|
67
|
+
const executeReadySteps = async () => {
|
|
68
|
+
const readySteps = plan.steps.filter(step => step.status === 'pending' &&
|
|
69
|
+
(!step.dependencies || step.dependencies.every(depId => plan.steps.find(s => s.id === depId)?.status === 'completed')));
|
|
70
|
+
if (readySteps.length === 0) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
for (const step of readySteps) {
|
|
74
|
+
step.status = 'running';
|
|
75
|
+
}
|
|
76
|
+
const promises = readySteps.map(async (step) => {
|
|
77
|
+
const result = await this.execute(step.toolCall, context);
|
|
78
|
+
step.result = result;
|
|
79
|
+
step.status = result.status === 'success' ? 'completed' : 'failed';
|
|
80
|
+
results.push(result);
|
|
81
|
+
if (step.status === 'completed') {
|
|
82
|
+
await executeReadySteps();
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
await Promise.all(promises);
|
|
86
|
+
};
|
|
87
|
+
await executeReadySteps();
|
|
88
|
+
const failedSteps = plan.steps.filter(s => s.status === 'failed');
|
|
89
|
+
if (failedSteps.length > 0) {
|
|
90
|
+
this.logger.warn(`Plan execution completed with ${failedSteps.length} failed steps.`);
|
|
91
|
+
}
|
|
92
|
+
const pendingSteps = plan.steps.filter(s => s.status === 'pending');
|
|
93
|
+
if (pendingSteps.length > 0) {
|
|
94
|
+
this.logger.error(`Plan execution deadlocked, ${pendingSteps.length} steps remaining pending.`);
|
|
95
|
+
}
|
|
96
|
+
return results;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=executor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"executor.js","sourceRoot":"","sources":["../src/executor.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AA0B1C,MAAM,OAAO,YAAY;IACf,QAAQ,CAAe;IACvB,MAAM,CAAgB;IACtB,MAAM,CAAU;IAChB,SAAS,CAAmB;IAC5B,YAAY,CAAe;IAEnC,YAAY,QAAsB,EAAE,MAAqB,EAAE,MAAe;QACxE,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IA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AAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC;QACpE,IAAI,YAAY,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC5B,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,8BAA8B,YAAY,CAAC,MAAM,2BAA2B,CAAC,CAAC;QAClG,CAAC;QAED,OAAO,OAAO,CAAC;IACjB,CAAC;CACF"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from './context.js';
|
|
2
|
+
export * from './validator.js';
|
|
3
|
+
export * from './middleware-pipeline.js';
|
|
4
|
+
export * from './tool-registry.js';
|
|
5
|
+
export * from './executor.js';
|
|
6
|
+
export * from './retry.js';
|
|
7
|
+
export * from './utils.js';
|
|
8
|
+
export * from './structured-output.js';
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,0BAA0B,CAAC;AACzC,cAAc,oBAAoB,CAAC;AACnC,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,wBAAwB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from './context.js';
|
|
2
|
+
export * from './validator.js';
|
|
3
|
+
export * from './middleware-pipeline.js';
|
|
4
|
+
export * from './tool-registry.js';
|
|
5
|
+
export * from './executor.js';
|
|
6
|
+
export * from './retry.js';
|
|
7
|
+
export * from './utils.js';
|
|
8
|
+
export * from './structured-output.js';
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,0BAA0B,CAAC;AACzC,cAAc,oBAAoB,CAAC;AACnC,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,wBAAwB,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { IMiddleware, MiddlewareContext } from '@astrive-ai/types';
|
|
2
|
+
export declare class MiddlewarePipeline {
|
|
3
|
+
private middlewares;
|
|
4
|
+
use(middleware: IMiddleware): void;
|
|
5
|
+
execute(context: MiddlewareContext): Promise<void>;
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=middleware-pipeline.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"middleware-pipeline.d.ts","sourceRoot":"","sources":["../src/middleware-pipeline.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAEnE,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,WAAW,CAAqB;IAEjC,GAAG,CAAC,UAAU,EAAE,WAAW,GAAG,IAAI;IAK5B,OAAO,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;CAsBhE"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export class MiddlewarePipeline {
|
|
2
|
+
middlewares = [];
|
|
3
|
+
use(middleware) {
|
|
4
|
+
this.middlewares.push(middleware);
|
|
5
|
+
this.middlewares.sort((a, b) => a.order - b.order);
|
|
6
|
+
}
|
|
7
|
+
async execute(context) {
|
|
8
|
+
let index = -1;
|
|
9
|
+
const dispatch = async (i) => {
|
|
10
|
+
if (i <= index) {
|
|
11
|
+
throw new Error('next() called multiple times');
|
|
12
|
+
}
|
|
13
|
+
index = i;
|
|
14
|
+
if (i < this.middlewares.length) {
|
|
15
|
+
const middleware = this.middlewares[i];
|
|
16
|
+
try {
|
|
17
|
+
await middleware.execute(context, () => dispatch(i + 1));
|
|
18
|
+
}
|
|
19
|
+
catch (error) {
|
|
20
|
+
context.metadata.error = error;
|
|
21
|
+
throw error;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
await dispatch(0);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=middleware-pipeline.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"middleware-pipeline.js","sourceRoot":"","sources":["../src/middleware-pipeline.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,kBAAkB;IACrB,WAAW,GAAkB,EAAE,CAAC;IAEjC,GAAG,CAAC,UAAuB;QAChC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAClC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC;IACrD,CAAC;IAEM,KAAK,CAAC,OAAO,CAAC,OAA0B;QAC7C,IAAI,KAAK,GAAG,CAAC,CAAC,CAAC;QAEf,MAAM,QAAQ,GAAG,KAAK,EAAE,CAAS,EAAiB,EAAE;YAClD,IAAI,CAAC,IAAI,KAAK,EAAE,CAAC;gBACf,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;YAClD,CAAC;YACD,KAAK,GAAG,CAAC,CAAC;YAEV,IAAI,CAAC,GAAG,IAAI,CAAC,WAAW,CAAC,MAAM,EAAE,CAAC;gBAChC,MAAM,UAAU,GAAG,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;gBACvC,IAAI,CAAC;oBACH,MAAM,UAAU,CAAC,OAAO,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;gBAC3D,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBACf,OAAO,CAAC,QAAQ,CAAC,KAAK,GAAG,KAAK,CAAC;oBAC/B,MAAM,KAAK,CAAC;gBACd,CAAC;YACH,CAAC;QACH,CAAC,CAAC;QAEF,MAAM,QAAQ,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC;CACF"}
|
package/dist/retry.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare class AstriveError extends Error {
|
|
2
|
+
retryable: boolean;
|
|
3
|
+
constructor(message: string, retryable?: boolean);
|
|
4
|
+
}
|
|
5
|
+
export interface RetryOptions {
|
|
6
|
+
maxRetries: number;
|
|
7
|
+
baseDelay: number;
|
|
8
|
+
maxDelay: number;
|
|
9
|
+
backoffMultiplier: number;
|
|
10
|
+
retryOn?: (error: Error) => boolean;
|
|
11
|
+
}
|
|
12
|
+
export declare class RetryHandler {
|
|
13
|
+
execute<T>(fn: () => Promise<T>, options?: RetryOptions): Promise<T>;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=retry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retry.d.ts","sourceRoot":"","sources":["../src/retry.ts"],"names":[],"mappings":"AAAA,qBAAa,YAAa,SAAQ,KAAK;IAC9B,SAAS,EAAE,OAAO,CAAC;gBACd,OAAO,EAAE,MAAM,EAAE,SAAS,GAAE,OAAe;CAKxD;AAED,MAAM,WAAW,YAAY;IAC3B,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,OAAO,CAAC;CACrC;AAED,qBAAa,YAAY;IACV,OAAO,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,CAAC,CAAC;CA2ClF"}
|
package/dist/retry.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
export class AstriveError extends Error {
|
|
2
|
+
retryable;
|
|
3
|
+
constructor(message, retryable = false) {
|
|
4
|
+
super(message);
|
|
5
|
+
this.name = 'AstriveError';
|
|
6
|
+
this.retryable = retryable;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
export class RetryHandler {
|
|
10
|
+
async execute(fn, options) {
|
|
11
|
+
const opts = {
|
|
12
|
+
maxRetries: 3,
|
|
13
|
+
baseDelay: 1000,
|
|
14
|
+
maxDelay: 10000,
|
|
15
|
+
backoffMultiplier: 2,
|
|
16
|
+
...options
|
|
17
|
+
};
|
|
18
|
+
let attempt = 0;
|
|
19
|
+
while (true) {
|
|
20
|
+
try {
|
|
21
|
+
return await fn();
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
if (attempt >= opts.maxRetries) {
|
|
25
|
+
throw error;
|
|
26
|
+
}
|
|
27
|
+
let retryable = false;
|
|
28
|
+
if (opts.retryOn) {
|
|
29
|
+
retryable = opts.retryOn(error);
|
|
30
|
+
}
|
|
31
|
+
else if (error instanceof AstriveError) {
|
|
32
|
+
retryable = error.retryable;
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
retryable = true;
|
|
36
|
+
}
|
|
37
|
+
if (!retryable) {
|
|
38
|
+
throw error;
|
|
39
|
+
}
|
|
40
|
+
const delay = Math.min(opts.baseDelay * Math.pow(opts.backoffMultiplier, attempt), opts.maxDelay);
|
|
41
|
+
const jitter = Math.random() * delay * 0.2;
|
|
42
|
+
const sleepTime = delay + jitter;
|
|
43
|
+
await new Promise(resolve => setTimeout(resolve, sleepTime));
|
|
44
|
+
attempt++;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=retry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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G,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,iBAAiB,EAAE,OAAO,CAAC,EAC1D,IAAI,CAAC,QAAQ,CACd,CAAC;gBACF,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,EAAE,GAAG,KAAK,GAAG,GAAG,CAAC;gBAC3C,MAAM,SAAS,GAAG,KAAK,GAAG,MAAM,CAAC;gBAEjC,MAAM,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC,CAAC;gBAC7D,OAAO,EAAE,CAAC;YACZ,CAAC;QACH,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { IProvider, JsonSchema } from '@astrive-ai/types';
|
|
2
|
+
export interface StructuredOutputOptions {
|
|
3
|
+
schema: JsonSchema;
|
|
4
|
+
maxRetries?: number;
|
|
5
|
+
model?: string;
|
|
6
|
+
}
|
|
7
|
+
export declare class StructuredOutputGenerator {
|
|
8
|
+
private provider;
|
|
9
|
+
private validator;
|
|
10
|
+
constructor(provider: IProvider);
|
|
11
|
+
generate<T>(prompt: string, options: StructuredOutputOptions): Promise<T>;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=structured-output.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"structured-output.d.ts","sourceRoot":"","sources":["../src/structured-output.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAI1D,MAAM,WAAW,uBAAuB;IACtC,MAAM,EAAE,UAAU,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,qBAAa,yBAAyB;IACpC,OAAO,CAAC,QAAQ,CAAY;IAC5B,OAAO,CAAC,SAAS,CAAmB;gBAExB,QAAQ,EAAE,SAAS;IAKlB,QAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,uBAAuB,GAAG,OAAO,CAAC,CAAC,CAAC;CA4DvF"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { RequestValidator } from './validator.js';
|
|
2
|
+
import { AstriveError } from './retry.js';
|
|
3
|
+
export class StructuredOutputGenerator {
|
|
4
|
+
provider;
|
|
5
|
+
validator;
|
|
6
|
+
constructor(provider) {
|
|
7
|
+
this.provider = provider;
|
|
8
|
+
this.validator = new RequestValidator();
|
|
9
|
+
}
|
|
10
|
+
async generate(prompt, options) {
|
|
11
|
+
const maxRetries = options.maxRetries || 3;
|
|
12
|
+
let currentAttempt = 0;
|
|
13
|
+
// Convert schema to string
|
|
14
|
+
const schemaString = JSON.stringify(options.schema, null, 2);
|
|
15
|
+
let currentPrompt = `${prompt}\n\nYou must return a valid JSON object that strictly adheres to the following JSON schema:\n${schemaString}\n\nReturn ONLY the JSON object, with no markdown formatting like \`\`\`json.`;
|
|
16
|
+
while (currentAttempt < maxRetries) {
|
|
17
|
+
try {
|
|
18
|
+
const response = await this.provider.chat({
|
|
19
|
+
messages: [{ role: 'user', content: currentPrompt }],
|
|
20
|
+
model: options.model,
|
|
21
|
+
responseFormat: { type: 'json_object' }
|
|
22
|
+
});
|
|
23
|
+
const rawOutput = response.content.trim();
|
|
24
|
+
let parsed;
|
|
25
|
+
try {
|
|
26
|
+
// Attempt to parse raw output as JSON
|
|
27
|
+
// Strip markdown code blocks if the model ignored instructions
|
|
28
|
+
let cleanOutput = rawOutput;
|
|
29
|
+
if (cleanOutput.startsWith('```json')) {
|
|
30
|
+
cleanOutput = cleanOutput.substring(7);
|
|
31
|
+
}
|
|
32
|
+
if (cleanOutput.startsWith('```')) {
|
|
33
|
+
cleanOutput = cleanOutput.substring(3);
|
|
34
|
+
}
|
|
35
|
+
if (cleanOutput.endsWith('```')) {
|
|
36
|
+
cleanOutput = cleanOutput.substring(0, cleanOutput.length - 3);
|
|
37
|
+
}
|
|
38
|
+
cleanOutput = cleanOutput.trim();
|
|
39
|
+
parsed = JSON.parse(cleanOutput);
|
|
40
|
+
}
|
|
41
|
+
catch (e) {
|
|
42
|
+
throw new AstriveError(`Failed to parse JSON: ${e.message}\nRaw output: ${rawOutput}`, true);
|
|
43
|
+
}
|
|
44
|
+
// Validate against schema
|
|
45
|
+
const validation = this.validator.validateToolArgs(options.schema, parsed);
|
|
46
|
+
if (!validation.valid) {
|
|
47
|
+
throw new AstriveError(`JSON does not match schema. Errors: ${validation.errors.join(', ')}`, true);
|
|
48
|
+
}
|
|
49
|
+
return parsed;
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
currentAttempt++;
|
|
53
|
+
if (currentAttempt >= maxRetries || !(error instanceof AstriveError) || !error.retryable) {
|
|
54
|
+
throw error;
|
|
55
|
+
}
|
|
56
|
+
// Repair output by telling the model about the error
|
|
57
|
+
currentPrompt = `The previous attempt failed with the following error:\n${error.message}\n\nPlease try again and fix the errors. Remember, you must return a valid JSON object adhering to this schema:\n${schemaString}`;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
throw new Error('Failed to generate structured output after maximum retries');
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=structured-output.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"structured-output.js","sourceRoot":"","sources":["../src/structured-output.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAQ1C,MAAM,OAAO,yBAAyB;IAC5B,QAAQ,CAAY;IACpB,SAAS,CAAmB;IAEpC,YAAY,QAAmB;QAC7B,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,SAAS,GAAG,IAAI,gBAAgB,EAAE,CAAC;IAC1C,CAAC;IAEM,KAAK,CAAC,QAAQ,CAAI,MAAc,EAAE,OAAg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,CAAC;oBACD,WAAW,GAAG,WAAW,CAAC,IAAI,EAAE,CAAC;oBAEjC,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;gBACnC,CAAC;gBAAC,OAAO,CAAM,EAAE,CAAC;oBAChB,MAAM,IAAI,YAAY,CAAC,yBAAyB,CAAC,CAAC,OAAO,iBAAiB,SAAS,EAAE,EAAE,IAAI,CAAC,CAAC;gBAC/F,CAAC;gBAED,0BAA0B;gBAC1B,MAAM,UAAU,GAAG,IAAI,CAAC,SAAS,CAAC,gBAAgB,CAAC,OAAO,CAAC,MAAM,EAAE,MAAiC,CAAC,CAAC;gBACtG,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC;oBACtB,MAAM,IAAI,YAAY,CAAC,uCAAuC,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;gBACtG,CAAC;gBAED,OAAO,MAAW,CAAC;YACrB,CAAC;YAAC,OAAO,KAAU,EAAE,CAAC;gBACpB,cAAc,EAAE,CAAC;gBACjB,IAAI,cAAc,IAAI,UAAU,IAAI,CAAC,CAAC,KAAK,YAAY,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,EAAE,CAAC;oBACzF,MAAM,KAAK,CAAC;gBACd,CAAC;gBAED,qDAAqD;gBACrD,aAAa,GAAG,0DAA0D,KAAK,CAAC,OAAO,oHAAoH,YAAY,EAAE,CAAC;YAC5N,CAAC;QACH,CAAC;QAED,MAAM,IAAI,KAAK,CAAC,4DAA4D,CAAC,CAAC;IAChF,CAAC;CACF"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ITool, ToolCategory, ToolDefinition, IEventEmitter } from '@astrive-ai/types';
|
|
2
|
+
export declare class ToolRegistry {
|
|
3
|
+
private tools;
|
|
4
|
+
private events?;
|
|
5
|
+
constructor(events?: IEventEmitter);
|
|
6
|
+
register(tool: ITool): void;
|
|
7
|
+
unregister(name: string): void;
|
|
8
|
+
get(name: string): ITool | undefined;
|
|
9
|
+
getAll(): ITool[];
|
|
10
|
+
getByCategory(category: ToolCategory): ITool[];
|
|
11
|
+
has(name: string): boolean;
|
|
12
|
+
getDefinitions(): ToolDefinition[];
|
|
13
|
+
clear(): void;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=tool-registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-registry.d.ts","sourceRoot":"","sources":["../src/tool-registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAEvF,qBAAa,YAAY;IACvB,OAAO,CAAC,KAAK,CAAiC;IAC9C,OAAO,CAAC,MAAM,CAAC,CAAgB;gBAEnB,MAAM,CAAC,EAAE,aAAa;IAI3B,QAAQ,CAAC,IAAI,EAAE,KAAK,GAAG,IAAI;IAU3B,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAS9B,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,KAAK,GAAG,SAAS;IAIpC,MAAM,IAAI,KAAK,EAAE;IAIjB,aAAa,CAAC,QAAQ,EAAE,YAAY,GAAG,KAAK,EAAE;IAI9C,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAI1B,cAAc,IAAI,cAAc,EAAE;IAIlC,KAAK,IAAI,IAAI;CAMrB"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
export class ToolRegistry {
|
|
2
|
+
tools = new Map();
|
|
3
|
+
events;
|
|
4
|
+
constructor(events) {
|
|
5
|
+
this.events = events;
|
|
6
|
+
}
|
|
7
|
+
register(tool) {
|
|
8
|
+
if (!tool.name || !tool.execute) {
|
|
9
|
+
throw new Error(`Invalid tool definition for ${tool.name}`);
|
|
10
|
+
}
|
|
11
|
+
this.tools.set(tool.name, tool);
|
|
12
|
+
if (this.events) {
|
|
13
|
+
this.events.emit('tool:registered', { name: tool.name });
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
unregister(name) {
|
|
17
|
+
if (this.tools.has(name)) {
|
|
18
|
+
this.tools.delete(name);
|
|
19
|
+
if (this.events) {
|
|
20
|
+
this.events.emit('tool:unregistered', { name });
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
get(name) {
|
|
25
|
+
return this.tools.get(name);
|
|
26
|
+
}
|
|
27
|
+
getAll() {
|
|
28
|
+
return Array.from(this.tools.values());
|
|
29
|
+
}
|
|
30
|
+
getByCategory(category) {
|
|
31
|
+
return this.getAll().filter(tool => tool.category === category);
|
|
32
|
+
}
|
|
33
|
+
has(name) {
|
|
34
|
+
return this.tools.has(name);
|
|
35
|
+
}
|
|
36
|
+
getDefinitions() {
|
|
37
|
+
return this.getAll().map(tool => tool.getSchema());
|
|
38
|
+
}
|
|
39
|
+
clear() {
|
|
40
|
+
this.tools.clear();
|
|
41
|
+
if (this.events) {
|
|
42
|
+
this.events.emit('tool:cleared');
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=tool-registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-registry.js","sourceRoot":"","sources":["../src/tool-registry.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,YAAY;IACf,KAAK,GAAuB,IAAI,GAAG,EAAE,CAAC;IACtC,MAAM,CAAiB;IAE/B,YAAY,MAAsB;QAChC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAEM,QAAQ,CAAC,IAAW;QACzB,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;YAChC,MAAM,IAAI,KAAK,CAAC,+BAA+B,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;QAC9D,CAAC;QACD,IAAI,CAAC,KAAK,CAAC,GAAG,CA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,CAAC,MAAM,EAAE,CAAC;YAChB,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;QACnC,CAAC;IACH,CAAC;CACF"}
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
3
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
4
|
+
import { Buffer } from 'buffer';
|
|
5
|
+
export declare function generateId(): string;
|
|
6
|
+
export declare function sleep(ms: number): Promise<void>;
|
|
7
|
+
export declare function createAbortController(timeoutMs: number): {
|
|
8
|
+
controller: AbortController;
|
|
9
|
+
cleanup: () => void;
|
|
10
|
+
};
|
|
11
|
+
export declare function formatBytes(bytes: number): string;
|
|
12
|
+
export declare function isUrl(str: string): boolean;
|
|
13
|
+
export declare function resolveImageInput(input: string | Buffer): Promise<Buffer>;
|
|
14
|
+
export declare function toBase64(buffer: Buffer): string;
|
|
15
|
+
export declare function fromBase64(str: string): Buffer;
|
|
16
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;AACA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,wBAAgB,UAAU,IAAI,MAAM,CAEnC;AAED,wBAAgB,KAAK,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAE/C;AAED,wBAAgB,qBAAqB,CAAC,SAAS,EAAE,MAAM,GAAG;IAAE,UAAU,EAAE,eAAe,CAAC;IAAC,OAAO,EAAE,MAAM,IAAI,CAAA;CAAE,CAU7G;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAMjD;AAED,wBAAgB,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAO1C;AAED,wBAAsB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CA8B/E;AAED,wBAAgB,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAE/C;AAED,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE9C"}
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import * as crypto from 'crypto';
|
|
2
|
+
import { Buffer } from 'buffer';
|
|
3
|
+
export function generateId() {
|
|
4
|
+
return crypto.randomUUID();
|
|
5
|
+
}
|
|
6
|
+
export function sleep(ms) {
|
|
7
|
+
return new Promise(resolve => setTimeout(resolve, ms));
|
|
8
|
+
}
|
|
9
|
+
export function createAbortController(timeoutMs) {
|
|
10
|
+
const controller = new AbortController();
|
|
11
|
+
const timeoutId = setTimeout(() => {
|
|
12
|
+
controller.abort();
|
|
13
|
+
}, timeoutMs);
|
|
14
|
+
return {
|
|
15
|
+
controller,
|
|
16
|
+
cleanup: () => clearTimeout(timeoutId)
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
export function formatBytes(bytes) {
|
|
20
|
+
if (bytes === 0)
|
|
21
|
+
return '0 Bytes';
|
|
22
|
+
const k = 1024;
|
|
23
|
+
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
|
|
24
|
+
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
25
|
+
return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];
|
|
26
|
+
}
|
|
27
|
+
export function isUrl(str) {
|
|
28
|
+
try {
|
|
29
|
+
new URL(str);
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
export async function resolveImageInput(input) {
|
|
37
|
+
if (Buffer.isBuffer(input)) {
|
|
38
|
+
return input;
|
|
39
|
+
}
|
|
40
|
+
if (isUrl(input)) {
|
|
41
|
+
const response = await fetch(input);
|
|
42
|
+
if (!response.ok) {
|
|
43
|
+
throw new Error(`Failed to fetch image from ${input}: ${response.statusText}`);
|
|
44
|
+
}
|
|
45
|
+
const arrayBuffer = await response.arrayBuffer();
|
|
46
|
+
return Buffer.from(arrayBuffer);
|
|
47
|
+
}
|
|
48
|
+
if (typeof input === 'string' && input.startsWith('data:image')) {
|
|
49
|
+
const match = input.match(/^data:image\/[^;]+;base64,(.+)$/);
|
|
50
|
+
if (match) {
|
|
51
|
+
return Buffer.from(match[1], 'base64');
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
try {
|
|
55
|
+
const buf = Buffer.from(input, 'base64');
|
|
56
|
+
if (buf.toString('base64') === input || buf.toString('base64') === input.replace(/=/g, '')) {
|
|
57
|
+
return buf;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
catch (e) {
|
|
61
|
+
}
|
|
62
|
+
throw new Error('Unsupported image input format');
|
|
63
|
+
}
|
|
64
|
+
export function toBase64(buffer) {
|
|
65
|
+
return buffer.toString('base64');
|
|
66
|
+
}
|
|
67
|
+
export function fromBase64(str) {
|
|
68
|
+
return Buffer.from(str, 'base64');
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AACjC,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,MAAM,UAAU,UAAU;IACxB,OAAO,MAAM,CAAC,UAAU,EAAE,CAAC;AAC7B,CAAC;AAED,MAAM,UAAU,KAAK,CAAC,EAAU;IAC9B,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;AACzD,CAAC;AAED,MAAM,U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