@kortyx/hooks 0.4.0 → 0.5.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/CHANGELOG.md +22 -0
- package/README.md +21 -4
- package/dist/index.d.ts +92 -5
- package/dist/index.js +767 -13
- package/dist/index.js.map +1 -0
- package/dist/internal.d.ts +24 -3
- package/dist/internal.js +125 -5
- package/dist/internal.js.map +1 -0
- package/package.json +11 -7
- package/dist/context.d.ts +0 -26
- package/dist/context.d.ts.map +0 -1
- package/dist/context.js +0 -82
- package/dist/hooks.d.ts +0 -29
- package/dist/hooks.d.ts.map +0 -1
- package/dist/hooks.js +0 -108
- package/dist/index.d.ts.map +0 -1
- package/dist/internal.d.ts.map +0 -1
- package/dist/reason-engine.d.ts +0 -19
- package/dist/reason-engine.d.ts.map +0 -1
- package/dist/reason-engine.js +0 -81
package/dist/reason-engine.js
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.runReasonEngine = runReasonEngine;
|
|
4
|
-
const chunkToText = (chunk) => {
|
|
5
|
-
if (typeof chunk === "string")
|
|
6
|
-
return chunk;
|
|
7
|
-
if (typeof chunk.text === "string")
|
|
8
|
-
return chunk.text;
|
|
9
|
-
if (typeof chunk.content === "string")
|
|
10
|
-
return chunk.content;
|
|
11
|
-
return "";
|
|
12
|
-
};
|
|
13
|
-
const emitNodeEvent = (emitEvent, nodeId, event, payload) => {
|
|
14
|
-
if (!emitEvent)
|
|
15
|
-
return;
|
|
16
|
-
emitEvent(event, {
|
|
17
|
-
...payload,
|
|
18
|
-
...(typeof nodeId === "string" && nodeId.length > 0
|
|
19
|
-
? { node: nodeId }
|
|
20
|
-
: {}),
|
|
21
|
-
});
|
|
22
|
-
};
|
|
23
|
-
async function runReasonEngine(args) {
|
|
24
|
-
const stream = args.stream ?? args.model.options?.streaming ?? true;
|
|
25
|
-
const emit = args.emit ?? true;
|
|
26
|
-
const temperature = args.temperature ??
|
|
27
|
-
args.model.options?.temperature ??
|
|
28
|
-
args.defaultTemperature;
|
|
29
|
-
const model = args.getProvider(args.model.providerId, args.model.modelId, {
|
|
30
|
-
...(temperature !== undefined ? { temperature } : {}),
|
|
31
|
-
streaming: stream,
|
|
32
|
-
});
|
|
33
|
-
const messages = [];
|
|
34
|
-
if (typeof args.system === "string" && args.system.length > 0) {
|
|
35
|
-
messages.push({ role: "system", content: args.system });
|
|
36
|
-
}
|
|
37
|
-
messages.push({ role: "user", content: String(args.input ?? "") });
|
|
38
|
-
if (stream) {
|
|
39
|
-
let final = "";
|
|
40
|
-
let raw;
|
|
41
|
-
if (emit) {
|
|
42
|
-
emitNodeEvent(args.emitEvent, args.nodeId, "text-start", {});
|
|
43
|
-
}
|
|
44
|
-
const response = await model.stream(messages);
|
|
45
|
-
for await (const chunk of response) {
|
|
46
|
-
const text = chunkToText(chunk);
|
|
47
|
-
if (!text)
|
|
48
|
-
continue;
|
|
49
|
-
final += text;
|
|
50
|
-
if (typeof chunk === "object" && chunk && "raw" in chunk) {
|
|
51
|
-
raw = chunk.raw;
|
|
52
|
-
}
|
|
53
|
-
if (emit) {
|
|
54
|
-
emitNodeEvent(args.emitEvent, args.nodeId, "text-delta", {
|
|
55
|
-
delta: text,
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
if (emit) {
|
|
60
|
-
emitNodeEvent(args.emitEvent, args.nodeId, "text-end", {});
|
|
61
|
-
}
|
|
62
|
-
return {
|
|
63
|
-
text: final,
|
|
64
|
-
...(raw !== undefined ? { raw } : {}),
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
const response = await model.invoke(messages);
|
|
68
|
-
if (emit) {
|
|
69
|
-
emitNodeEvent(args.emitEvent, args.nodeId, "text-start", {});
|
|
70
|
-
if (response.content) {
|
|
71
|
-
emitNodeEvent(args.emitEvent, args.nodeId, "text-delta", {
|
|
72
|
-
delta: response.content,
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
emitNodeEvent(args.emitEvent, args.nodeId, "text-end", {});
|
|
76
|
-
}
|
|
77
|
-
return {
|
|
78
|
-
text: response.content,
|
|
79
|
-
...(response.raw !== undefined ? { raw: response.raw } : {}),
|
|
80
|
-
};
|
|
81
|
-
}
|