@threaded/ai 1.0.30 → 1.1.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 +240 -0
- package/dist/approval.d.ts +18 -0
- package/dist/approval.d.ts.map +1 -0
- package/dist/approval.js +35 -0
- package/dist/approval.js.map +1 -0
- package/dist/composition/compose.d.ts +3 -0
- package/dist/composition/compose.d.ts.map +1 -0
- package/dist/composition/compose.js +38 -0
- package/dist/composition/compose.js.map +1 -0
- package/dist/composition/model.d.ts +9 -0
- package/dist/composition/model.d.ts.map +1 -0
- package/dist/composition/model.js +192 -0
- package/dist/composition/model.js.map +1 -0
- package/dist/composition/retry.d.ts +6 -0
- package/dist/composition/retry.d.ts.map +1 -0
- package/dist/composition/retry.js +18 -0
- package/dist/composition/retry.js.map +1 -0
- package/dist/composition/scope.d.ts +3 -0
- package/dist/composition/scope.d.ts.map +1 -0
- package/dist/composition/scope.js +83 -0
- package/dist/composition/scope.js.map +1 -0
- package/dist/composition/tap.d.ts +3 -0
- package/dist/composition/tap.d.ts.map +1 -0
- package/dist/composition/tap.js +7 -0
- package/dist/composition/tap.js.map +1 -0
- package/dist/composition/when.d.ts +3 -0
- package/dist/composition/when.d.ts.map +1 -0
- package/dist/composition/when.js +9 -0
- package/dist/composition/when.js.map +1 -0
- package/dist/embed.d.ts +16 -0
- package/dist/embed.d.ts.map +1 -0
- package/dist/embed.js +72 -0
- package/dist/embed.js.map +1 -0
- package/dist/examples.d.ts +2 -0
- package/dist/examples.d.ts.map +1 -0
- package/dist/examples.js +6 -0
- package/dist/examples.js.map +1 -0
- package/dist/helpers.d.ts +17 -0
- package/dist/helpers.d.ts.map +1 -0
- package/dist/helpers.js +104 -0
- package/dist/helpers.js.map +1 -0
- package/dist/image-model-schema.d.ts +19 -0
- package/dist/image-model-schema.d.ts.map +1 -0
- package/dist/image-model-schema.js +103 -0
- package/dist/image-model-schema.js.map +1 -0
- package/dist/image.d.ts +3 -0
- package/dist/image.d.ts.map +1 -0
- package/dist/image.js +120 -0
- package/dist/image.js.map +1 -0
- package/dist/index.d.ts +18 -352
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +17 -2073
- package/dist/index.js.map +1 -1
- package/dist/mcp.d.ts +3 -0
- package/dist/mcp.d.ts.map +1 -0
- package/dist/mcp.js +29 -0
- package/dist/mcp.js.map +1 -0
- package/dist/providers/anthropic.d.ts +3 -0
- package/dist/providers/anthropic.d.ts.map +1 -0
- package/dist/providers/anthropic.js +226 -0
- package/dist/providers/anthropic.js.map +1 -0
- package/dist/providers/google.d.ts +3 -0
- package/dist/providers/google.d.ts.map +1 -0
- package/dist/providers/google.js +244 -0
- package/dist/providers/google.js.map +1 -0
- package/dist/providers/huggingface.d.ts +3 -0
- package/dist/providers/huggingface.d.ts.map +1 -0
- package/dist/providers/huggingface.js +59 -0
- package/dist/providers/huggingface.js.map +1 -0
- package/dist/providers/index.d.ts +3 -0
- package/dist/providers/index.d.ts.map +1 -0
- package/dist/providers/index.js +29 -0
- package/dist/providers/index.js.map +1 -0
- package/dist/providers/local.d.ts +3 -0
- package/dist/providers/local.d.ts.map +1 -0
- package/dist/providers/local.js +152 -0
- package/dist/providers/local.js.map +1 -0
- package/dist/providers/openai.d.ts +3 -0
- package/dist/providers/openai.d.ts.map +1 -0
- package/dist/providers/openai.js +165 -0
- package/dist/providers/openai.js.map +1 -0
- package/dist/providers/xai.d.ts +3 -0
- package/dist/providers/xai.d.ts.map +1 -0
- package/dist/providers/xai.js +161 -0
- package/dist/providers/xai.js.map +1 -0
- package/dist/schema.d.ts +7 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +44 -0
- package/dist/schema.js.map +1 -0
- package/dist/thread.d.ts +25 -0
- package/dist/thread.d.ts.map +1 -0
- package/dist/thread.js +87 -0
- package/dist/thread.js.map +1 -0
- package/dist/types.d.ts +193 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +8 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/rateLimited.d.ts +27 -0
- package/dist/utils/rateLimited.d.ts.map +1 -0
- package/dist/utils/rateLimited.js +74 -0
- package/dist/utils/rateLimited.js.map +1 -0
- package/dist/utils.d.ts +8 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +78 -0
- package/dist/utils.js.map +1 -0
- package/package.json +34 -12
- package/.claude/settings.local.json +0 -15
- package/.lore +0 -65
- package/dist/index.cjs +0 -2149
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -352
- package/tsconfig.json +0 -29
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { compose } from "./compose";
|
|
2
|
+
import { Inherit, } from "../types";
|
|
3
|
+
import { toolConfigToToolDefinition } from "../utils";
|
|
4
|
+
const scopeContext = (config, ctx) => {
|
|
5
|
+
const inherit = config.inherit ?? Inherit.Conversation;
|
|
6
|
+
let scopedCtx = {
|
|
7
|
+
history: [],
|
|
8
|
+
tools: [],
|
|
9
|
+
toolExecutors: {},
|
|
10
|
+
toolLimits: {},
|
|
11
|
+
toolCallCounts: {},
|
|
12
|
+
};
|
|
13
|
+
// inheritance
|
|
14
|
+
if (inherit & Inherit.Conversation) {
|
|
15
|
+
scopedCtx.history = ctx.history;
|
|
16
|
+
scopedCtx.lastResponse = ctx.lastResponse;
|
|
17
|
+
scopedCtx.lastRequest = ctx.lastRequest;
|
|
18
|
+
}
|
|
19
|
+
if (inherit & Inherit.Tools) {
|
|
20
|
+
scopedCtx.tools = [...(ctx.tools || [])];
|
|
21
|
+
scopedCtx.toolExecutors = { ...(ctx.toolExecutors || {}) };
|
|
22
|
+
scopedCtx.toolLimits = { ...(ctx.toolLimits || {}) };
|
|
23
|
+
scopedCtx.toolCallCounts = { ...(ctx.toolCallCounts || {}) };
|
|
24
|
+
scopedCtx.toolConfig = ctx.toolConfig ? { ...ctx.toolConfig } : undefined;
|
|
25
|
+
}
|
|
26
|
+
scopedCtx.stream = ctx.stream;
|
|
27
|
+
scopedCtx.abortSignal = ctx.abortSignal;
|
|
28
|
+
scopedCtx.usage = ctx.usage;
|
|
29
|
+
if (config.tools) {
|
|
30
|
+
const toolDefinitions = config.tools.map(toolConfigToToolDefinition);
|
|
31
|
+
const toolExecutors = config.tools.reduce((acc, tool) => {
|
|
32
|
+
acc[tool.name] = tool.execute;
|
|
33
|
+
return acc;
|
|
34
|
+
}, {});
|
|
35
|
+
const toolLimits = config.tools.reduce((acc, tool) => {
|
|
36
|
+
if (tool._maxCalls) {
|
|
37
|
+
acc[tool.name] = tool._maxCalls;
|
|
38
|
+
}
|
|
39
|
+
return acc;
|
|
40
|
+
}, {});
|
|
41
|
+
scopedCtx.tools = toolDefinitions;
|
|
42
|
+
scopedCtx.toolExecutors = toolExecutors;
|
|
43
|
+
scopedCtx.toolLimits = toolLimits;
|
|
44
|
+
}
|
|
45
|
+
if (config.toolConfig) {
|
|
46
|
+
scopedCtx.toolConfig = { ...config.toolConfig };
|
|
47
|
+
}
|
|
48
|
+
if (config.system) {
|
|
49
|
+
const [first, ...rest] = scopedCtx.history;
|
|
50
|
+
if (first?.role === "system") {
|
|
51
|
+
scopedCtx.history = [{ role: "system", content: config.system }, ...rest];
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
scopedCtx.history = [{ role: "system", content: config.system }, ...scopedCtx.history];
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
if (config.stream) {
|
|
58
|
+
scopedCtx.stream = config.stream;
|
|
59
|
+
}
|
|
60
|
+
return scopedCtx;
|
|
61
|
+
};
|
|
62
|
+
export const scope = (config, ...steps) => {
|
|
63
|
+
return async (ctx) => {
|
|
64
|
+
let scopedCtx = scopeContext(config, ctx);
|
|
65
|
+
if (config.until) {
|
|
66
|
+
do {
|
|
67
|
+
scopedCtx = await compose(...steps)(scopedCtx);
|
|
68
|
+
} while (!config.until(scopedCtx));
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
scopedCtx = await compose(...steps)(scopedCtx);
|
|
72
|
+
}
|
|
73
|
+
return {
|
|
74
|
+
...ctx,
|
|
75
|
+
history: config.silent ? ctx.history : scopedCtx.history,
|
|
76
|
+
lastResponse: config.silent ? ctx.lastResponse : scopedCtx.lastResponse,
|
|
77
|
+
lastRequest: config.silent ? ctx.lastRequest : scopedCtx.lastRequest,
|
|
78
|
+
stopReason: config.silent ? ctx.stopReason : scopedCtx.stopReason,
|
|
79
|
+
usage: scopedCtx.usage,
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
//# sourceMappingURL=scope.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scope.js","sourceRoot":"","sources":["../../src/composition/scope.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAEL,OAAO,GAGR,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,0BAA0B,EAAE,MAAM,UAAU,CAAC;AAEtD,MAAM,YAAY,GAAG,CACnB,MAAmB,EACnB,GAAwB,EACH,EAAE;IACvB,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,IAAI,OAAO,CAAC,YAAY,CAAC;IAEvD,IAAI,SAAS,GAAwB;QACnC,OAAO,EAAE,EAAE;QACX,KAAK,EAAE,EAAE;QACT,aAAa,EAAE,EAAE;QACjB,UAAU,EAAE,EAAE;QACd,cAAc,EAAE,EAAE;KACnB,CAAC;IAEF,cAAc;IAEd,IAAI,OAAO,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC;QACnC,SAAS,CAAC,OAAO,GAAG,GAAG,CAAC,OAAO,CAAC;QAChC,SAAS,CAAC,YAAY,GAAG,GAAG,CAAC,YAAY,CAAC;QAC1C,SAAS,CAAC,WAAW,GAAG,GAAG,CAAC,WAAW,CAAC;IAC1C,CAAC;IAED,IAAI,OAAO,GAAG,OAAO,CAAC,KAAK,EAAE,CAAC;QAC5B,SAAS,CAAC,KAAK,GAAG,CAAC,GAAG,CAAC,GAAG,CA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OAAO,CAAC,GAAG,KAAK,CAAC,CAAC,SAAS,CAAC,CAAC;YACjD,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,EAAE;QACrC,CAAC;aAAM,CAAC;YACN,SAAS,GAAG,MAAM,OAAO,CAAC,GAAG,KAAK,CAAC,CAAC,SAAS,CAAC,CAAC;QACjD,CAAC;QAED,OAAO;YACL,GAAG,GAAG;YACN,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,OAAO;YACxD,YAAY,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC,CAAC,SAAS,CAAC,YAAY;YACvE,WAAW,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,SAAS,CAAC,WAAW;YACpE,UAAU,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,SAAS,CAAC,UAAU;YACjE,KAAK,EAAE,SAAS,CAAC,KAAK;SACvB,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tap.d.ts","sourceRoot":"","sources":["../../src/composition/tap.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAE7D,eAAO,MAAM,GAAG,GACd,IAAI,CAAC,GAAG,EAAE,mBAAmB,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,KACrD,YAKF,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tap.js","sourceRoot":"","sources":["../../src/composition/tap.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,GAAG,GAAG,CACjB,EAAsD,EACxC,EAAE;IAChB,OAAO,KAAK,EAAE,GAAwB,EAAgC,EAAE;QACtE,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC;QACd,OAAO,GAAG,CAAC;IACb,CAAC,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"when.d.ts","sourceRoot":"","sources":["../../src/composition/when.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAE7D,eAAO,MAAM,IAAI,GACf,WAAW,CAAC,GAAG,EAAE,mBAAmB,KAAK,OAAO,EAChD,QAAQ,YAAY,KACnB,YAOF,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"when.js","sourceRoot":"","sources":["../../src/composition/when.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,IAAI,GAAG,CAClB,SAAgD,EAChD,MAAoB,EACN,EAAE;IAChB,OAAO,KAAK,EAAE,GAAwB,EAAgC,EAAE;QACtE,IAAI,SAAS,CAAC,GAAG,CAAC,EAAE,CAAC;YACnB,OAAO,MAAM,MAAM,CAAC,GAAG,CAAC,CAAC;QAC3B,CAAC;QACD,OAAO,GAAG,CAAC;IACb,CAAC,CAAC;AACJ,CAAC,CAAC"}
|
package/dist/embed.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* generates embeddings for text using openai or huggingface models
|
|
3
|
+
*
|
|
4
|
+
* openai models use the prefix "openai/" (e.g., "openai/text-embedding-3-small")
|
|
5
|
+
* all other models use huggingface transformers
|
|
6
|
+
*
|
|
7
|
+
* accepts a single string or an array of strings for batch embedding
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* const vector = await embed("openai/text-embedding-3-small", "hello world");
|
|
11
|
+
* const vectors = await embed("openai/text-embedding-3-small", ["hello", "world"]);
|
|
12
|
+
*/
|
|
13
|
+
export declare const embed: (model: string, text: string | string[], config?: {
|
|
14
|
+
dimensions?: number;
|
|
15
|
+
}) => Promise<number[] | number[][]>;
|
|
16
|
+
//# sourceMappingURL=embed.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"embed.d.ts","sourceRoot":"","sources":["../src/embed.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,KAAK,GAChB,OAAO,MAAM,EACb,MAAM,MAAM,GAAG,MAAM,EAAE,EACvB,SAAS;IAAE,UAAU,CAAC,EAAE,MAAM,CAAA;CAAE,KAC/B,OAAO,CAAC,MAAM,EAAE,GAAG,MAAM,EAAE,EAAE,CAuE/B,CAAC"}
|
package/dist/embed.js
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { getKey } from "./utils";
|
|
2
|
+
const modelCache = new Map();
|
|
3
|
+
/**
|
|
4
|
+
* generates embeddings for text using openai or huggingface models
|
|
5
|
+
*
|
|
6
|
+
* openai models use the prefix "openai/" (e.g., "openai/text-embedding-3-small")
|
|
7
|
+
* all other models use huggingface transformers
|
|
8
|
+
*
|
|
9
|
+
* accepts a single string or an array of strings for batch embedding
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* const vector = await embed("openai/text-embedding-3-small", "hello world");
|
|
13
|
+
* const vectors = await embed("openai/text-embedding-3-small", ["hello", "world"]);
|
|
14
|
+
*/
|
|
15
|
+
export const embed = async (model, text, config) => {
|
|
16
|
+
const isBatch = Array.isArray(text);
|
|
17
|
+
if (model.startsWith("openai/")) {
|
|
18
|
+
const modelName = model.replace("openai/", "");
|
|
19
|
+
const apiKey = getKey("openai") || process.env.OPENAI_API_KEY;
|
|
20
|
+
if (!apiKey) {
|
|
21
|
+
throw new Error("OpenAI API key not found");
|
|
22
|
+
}
|
|
23
|
+
const body = {
|
|
24
|
+
model: modelName,
|
|
25
|
+
input: text,
|
|
26
|
+
};
|
|
27
|
+
if (config?.dimensions) {
|
|
28
|
+
body.dimensions = config.dimensions;
|
|
29
|
+
}
|
|
30
|
+
const response = await fetch("https://api.openai.com/v1/embeddings", {
|
|
31
|
+
method: "POST",
|
|
32
|
+
headers: {
|
|
33
|
+
"Content-Type": "application/json",
|
|
34
|
+
Authorization: `Bearer ${apiKey}`,
|
|
35
|
+
},
|
|
36
|
+
body: JSON.stringify(body),
|
|
37
|
+
});
|
|
38
|
+
if (!response.ok) {
|
|
39
|
+
const error = await response.text();
|
|
40
|
+
throw new Error(`OpenAI API error: ${error}`);
|
|
41
|
+
}
|
|
42
|
+
const data = (await response.json());
|
|
43
|
+
if (isBatch) {
|
|
44
|
+
return data.data.map((d) => d.embedding);
|
|
45
|
+
}
|
|
46
|
+
return data.data[0].embedding;
|
|
47
|
+
}
|
|
48
|
+
try {
|
|
49
|
+
const { pipeline } = await import("@huggingface/transformers");
|
|
50
|
+
if (!modelCache.has(model)) {
|
|
51
|
+
const extractor = await pipeline("feature-extraction", model, {
|
|
52
|
+
dtype: "fp32",
|
|
53
|
+
});
|
|
54
|
+
modelCache.set(model, extractor);
|
|
55
|
+
}
|
|
56
|
+
const extractor = modelCache.get(model);
|
|
57
|
+
if (isBatch) {
|
|
58
|
+
const results = [];
|
|
59
|
+
for (const t of text) {
|
|
60
|
+
const result = await extractor(t, { pooling: "mean", normalize: true });
|
|
61
|
+
results.push(Array.from(result.data));
|
|
62
|
+
}
|
|
63
|
+
return results;
|
|
64
|
+
}
|
|
65
|
+
const result = await extractor(text, { pooling: "mean", normalize: true });
|
|
66
|
+
return Array.from(result.data);
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
throw new Error(`huggingface transformers failed to load. install system dependencies or use openai models instead. original error: ${error.message}`);
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
//# sourceMappingURL=embed.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"embed.js","sourceRoot":"","sources":["../src/embed.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,E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CAAa,CAAC;IAC7C,CAAC;IAAC,OAAO,KAAU,EAAE,CAAC;QACpB,MAAM,IAAI,KAAK,CACb,sHAAsH,KAAK,CAAC,OAAO,EAAE,CACtI,CAAC;IACJ,CAAC;AACH,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"examples.d.ts","sourceRoot":"","sources":["../src/examples.ts"],"names":[],"mappings":""}
|
package/dist/examples.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { compose } from "./composition/compose";
|
|
2
|
+
import { model } from "./composition/model";
|
|
3
|
+
import { scope } from "./composition/scope";
|
|
4
|
+
import { appendToLastRequest, everyNMessages, noToolsCalled } from "./helpers";
|
|
5
|
+
const workflow = compose(everyNMessages(30, appendToLastRequest("stay focused")), scope({ tools: [], until: noToolsCalled() }, model({ model: "openai/gpt-4" })), scope({ tools: [], until: noToolsCalled() }, model({ model: "anthropic/sonnet" })));
|
|
6
|
+
//# sourceMappingURL=examples.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"examples.js","sourceRoot":"","sources":["../src/examples.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAChD,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAC5C,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAC5C,OAAO,EAAE,mBAAmB,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAE/E,MAAM,QAAQ,GAAG,OAAO,CACtB,cAAc,CAAC,EAAE,EAAE,mBAAmB,CAAC,cAAc,CAAC,CAAC,EACvD,KAAK,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,KAAK,EAAE,aAAa,EAAE,EAAE,EAAE,KAAK,CAAC,EAAE,KAAK,EAAE,cAAc,EAAE,CAAC,CAAC,EAC9E,KAAK,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,KAAK,EAAE,aAAa,EAAE,EAAE,EAAE,KAAK,CAAC,EAAE,KAAK,EAAE,kBAAkB,EAAE,CAAC,CAAC,CACnF,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ConversationContext, StepFunction } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* scope({ until: noToolsCalled() })
|
|
4
|
+
*/
|
|
5
|
+
export declare const noToolsCalled: () => (ctx: ConversationContext) => boolean;
|
|
6
|
+
export declare const everyNMessages: (n: number, step: StepFunction) => StepFunction;
|
|
7
|
+
export declare const everyNTokens: (n: number, step: StepFunction) => StepFunction;
|
|
8
|
+
export declare const appendToLastRequest: (content: string) => StepFunction;
|
|
9
|
+
/**
|
|
10
|
+
* toolNotUsedInNTurns({ toolName: "search_web", times: 10 }, appendToLastRequest("consider using web search..."))
|
|
11
|
+
*/
|
|
12
|
+
export declare const toolNotUsedInNTurns: ({ toolName, times }: {
|
|
13
|
+
toolName: string;
|
|
14
|
+
times: number;
|
|
15
|
+
}, step: StepFunction) => StepFunction;
|
|
16
|
+
export declare const toolWasCalled: (name: string) => (ctx: ConversationContext) => boolean;
|
|
17
|
+
//# sourceMappingURL=helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAG5D;;GAEG;AACH,eAAO,MAAM,aAAa,SAEvB,KAAK,mBAAmB,KAAG,OAI3B,CAAC;AAEJ,eAAO,MAAM,cAAc,GAAI,GAAG,MAAM,EAAE,MAAM,YAAY,KAAG,YAW9D,CAAC;AAEF,eAAO,MAAM,YAAY,GAAI,GAAG,MAAM,EAAE,MAAM,YAAY,KAAG,YAoB5D,CAAC;AAEF,eAAO,MAAM,mBAAmB,GAAI,SAAS,MAAM,KAAG,YAuBrD,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,mBAAmB,GAC9B,qBAAqB;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,EACxD,MAAM,YAAY,KACjB,YAsBF,CAAC;AAsCF,eAAO,MAAM,aAAa,GACvB,MAAM,MAAM,MACZ,KAAK,mBAAmB,KAAG,OAK3B,CAAC"}
|
package/dist/helpers.js
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { when } from "./composition/when";
|
|
2
|
+
/**
|
|
3
|
+
* scope({ until: noToolsCalled() })
|
|
4
|
+
*/
|
|
5
|
+
export const noToolsCalled = () => (ctx) => {
|
|
6
|
+
return (!ctx.lastResponse?.tool_calls || ctx.lastResponse.tool_calls.length === 0);
|
|
7
|
+
};
|
|
8
|
+
export const everyNMessages = (n, step) => {
|
|
9
|
+
let lastTriggeredAt = 0;
|
|
10
|
+
return when((ctx) => Math.floor(ctx.history.length / n) > Math.floor(lastTriggeredAt / n), async (ctx) => {
|
|
11
|
+
lastTriggeredAt = ctx.history.length;
|
|
12
|
+
return await step(ctx);
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
export const everyNTokens = (n, step) => {
|
|
16
|
+
let lastTriggeredAt = 0;
|
|
17
|
+
return when((ctx) => {
|
|
18
|
+
const totalTokens = ctx.history.reduce((acc, msg) => acc + Math.ceil(msg.content.length / 4), 0);
|
|
19
|
+
return Math.floor(totalTokens / n) > Math.floor(lastTriggeredAt / n);
|
|
20
|
+
}, async (ctx) => {
|
|
21
|
+
const totalTokens = ctx.history.reduce((acc, msg) => acc + Math.ceil(msg.content.length / 4), 0);
|
|
22
|
+
lastTriggeredAt = totalTokens;
|
|
23
|
+
return await step(ctx);
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
export const appendToLastRequest = (content) => {
|
|
27
|
+
return async (ctx) => {
|
|
28
|
+
let lastUserIndex = -1;
|
|
29
|
+
for (let i = ctx.history.length - 1; i >= 0; i--) {
|
|
30
|
+
if (ctx.history[i].role === "user") {
|
|
31
|
+
lastUserIndex = i;
|
|
32
|
+
break;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
if (lastUserIndex === -1)
|
|
36
|
+
return ctx;
|
|
37
|
+
const newHistory = [...ctx.history];
|
|
38
|
+
newHistory[lastUserIndex] = {
|
|
39
|
+
...newHistory[lastUserIndex],
|
|
40
|
+
content: newHistory[lastUserIndex].content + content,
|
|
41
|
+
};
|
|
42
|
+
return {
|
|
43
|
+
...ctx,
|
|
44
|
+
history: newHistory,
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* toolNotUsedInNTurns({ toolName: "search_web", times: 10 }, appendToLastRequest("consider using web search..."))
|
|
50
|
+
*/
|
|
51
|
+
export const toolNotUsedInNTurns = ({ toolName, times }, step) => {
|
|
52
|
+
let turnsSinceLastUsed = 0;
|
|
53
|
+
let lastProcessedTurn = -1;
|
|
54
|
+
return when((ctx) => {
|
|
55
|
+
const currentTurn = getCurrentTurn(ctx);
|
|
56
|
+
// only check once per turn
|
|
57
|
+
if (currentTurn === lastProcessedTurn)
|
|
58
|
+
return false;
|
|
59
|
+
lastProcessedTurn = currentTurn;
|
|
60
|
+
// check if tool was used in this turn
|
|
61
|
+
const toolUsedInTurn = wasToolUsedInCurrentTurn(ctx, toolName);
|
|
62
|
+
if (toolUsedInTurn) {
|
|
63
|
+
turnsSinceLastUsed = 0;
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
turnsSinceLastUsed++;
|
|
68
|
+
return turnsSinceLastUsed >= times;
|
|
69
|
+
}
|
|
70
|
+
}, step);
|
|
71
|
+
};
|
|
72
|
+
const getCurrentTurn = (ctx) => {
|
|
73
|
+
let turns = 0;
|
|
74
|
+
for (const msg of ctx.history) {
|
|
75
|
+
if (msg.role === "user")
|
|
76
|
+
turns++;
|
|
77
|
+
}
|
|
78
|
+
return turns;
|
|
79
|
+
};
|
|
80
|
+
const wasToolUsedInCurrentTurn = (ctx, toolName) => {
|
|
81
|
+
// find the last user message and check all messages after it for tool usage
|
|
82
|
+
let lastUserIndex = -1;
|
|
83
|
+
for (let i = ctx.history.length - 1; i >= 0; i--) {
|
|
84
|
+
if (ctx.history[i].role === "user") {
|
|
85
|
+
lastUserIndex = i;
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
if (lastUserIndex === -1)
|
|
90
|
+
return false;
|
|
91
|
+
// check messages after last user message for tool calls
|
|
92
|
+
for (let i = lastUserIndex + 1; i < ctx.history.length; i++) {
|
|
93
|
+
const msg = ctx.history[i];
|
|
94
|
+
if (msg.role === "assistant" && ctx.lastResponse?.tool_calls) {
|
|
95
|
+
return ctx.lastResponse.tool_calls.some((call) => call.function.name === toolName);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return false;
|
|
99
|
+
};
|
|
100
|
+
export const toolWasCalled = (name) => (ctx) => {
|
|
101
|
+
return (!!ctx.lastResponse?.tool_calls &&
|
|
102
|
+
ctx.lastResponse.tool_calls.some((call) => call.function.name === name));
|
|
103
|
+
};
|
|
104
|
+
//# sourceMappingURL=helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAE1C;;GAEG;AACH,MAAM,CAAC,MAAM,aAAa,GACxB,GAAG,EAAE,CACL,CAAC,GAAwB,EAAW,EAAE;IACpC,OAAO,CACL,CAAC,GAAG,CAAC,YAAY,EAAE,UAAU,IAAI,GAAG,CAAC,YAAY,CAAC,UAAU,CAAC,MAAM,KAAK,CAAC,CAC1E,CAAC;AACJ,CAAC,CAAC;AAEJ,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,CAAS,EAAE,IAAkB,EAAgB,EAAE;IAC5E,IAAI,eAAe,GAAG,CAAC,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IAAI,GAAG,CAAC,IAAI,KAAK,WAAW,IAAI,GAAG,CAAC,YAAY,EAAE,UAAU,EAAE,CAAC;YAC7D,OAAO,GAAG,CAAC,YAAY,CAAC,UAAU,CAAC,IAAI,CACrC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,KAAK,QAAQ,CAC1C,CAAC;QACJ,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,aAAa,GACxB,CAAC,IAAY,EAAE,EAAE,CACjB,CAAC,GAAwB,EAAW,EAAE;IACpC,OAAO,CACL,CAAC,CAAC,GAAG,CAAC,YAAY,EAAE,UAAU;QAC9B,GAAG,CAAC,YAAY,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,KAAK,IAAI,CAAC,CACxE,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export interface ConfigOption {
|
|
2
|
+
values: string[];
|
|
3
|
+
default: string;
|
|
4
|
+
description: string;
|
|
5
|
+
}
|
|
6
|
+
export interface ModelConfig {
|
|
7
|
+
[option: string]: ConfigOption;
|
|
8
|
+
}
|
|
9
|
+
export interface ProviderModels {
|
|
10
|
+
[model: string]: ModelConfig;
|
|
11
|
+
}
|
|
12
|
+
export interface ImageModelSchema {
|
|
13
|
+
[provider: string]: ProviderModels;
|
|
14
|
+
}
|
|
15
|
+
export declare const IMAGE_MODEL_SCHEMA: ImageModelSchema;
|
|
16
|
+
export declare const IMAGE_EDIT_MODEL_SCHEMA: ImageModelSchema;
|
|
17
|
+
export declare function getModelConfig(provider: string, model: string): ModelConfig | null;
|
|
18
|
+
export declare function getDefaultConfig(provider: string, model: string): Record<string, string>;
|
|
19
|
+
//# sourceMappingURL=image-model-schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"image-model-schema.d.ts","sourceRoot":"","sources":["../src/image-model-schema.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,WAAW;IAC1B,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY,CAAC;CAChC;AAED,MAAM,WAAW,cAAc;IAC7B,CAAC,KAAK,EAAE,MAAM,GAAG,WAAW,CAAC;CAC9B;AAED,MAAM,WAAW,gBAAgB;IAC/B,CAAC,QAAQ,EAAE,MAAM,GAAG,cAAc,CAAC;CACpC;AAED,eAAO,MAAM,kBAAkB,EAAE,gBAgEhC,CAAC;AAEF,eAAO,MAAM,uBAAuB,EAAE,gBAuBrC,CAAC;AAEF,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,WAAW,GAAG,IAAI,CAElF;AAED,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAQxF"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
export const IMAGE_MODEL_SCHEMA = {
|
|
2
|
+
openai: {
|
|
3
|
+
"dall-e-3": {
|
|
4
|
+
size: {
|
|
5
|
+
values: ["1024x1024", "1024x1792", "1792x1024"],
|
|
6
|
+
default: "1024x1024",
|
|
7
|
+
description: "Image dimensions",
|
|
8
|
+
},
|
|
9
|
+
quality: {
|
|
10
|
+
values: ["standard", "hd"],
|
|
11
|
+
default: "standard",
|
|
12
|
+
description: "Image quality level",
|
|
13
|
+
},
|
|
14
|
+
style: {
|
|
15
|
+
values: ["vivid", "natural"],
|
|
16
|
+
default: "vivid",
|
|
17
|
+
description: "Image style",
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
"gpt-image-1.5": {
|
|
21
|
+
size: {
|
|
22
|
+
values: ["1024x1024", "1536x1024", "1024x1536", "auto"],
|
|
23
|
+
default: "auto",
|
|
24
|
+
description: "Image dimensions",
|
|
25
|
+
},
|
|
26
|
+
quality: {
|
|
27
|
+
values: ["low", "medium", "high", "auto"],
|
|
28
|
+
default: "auto",
|
|
29
|
+
description: "Image quality level",
|
|
30
|
+
},
|
|
31
|
+
background: {
|
|
32
|
+
values: ["transparent", "opaque", "auto"],
|
|
33
|
+
default: "auto",
|
|
34
|
+
description: "Background type",
|
|
35
|
+
},
|
|
36
|
+
moderation: {
|
|
37
|
+
values: ["auto", "low"],
|
|
38
|
+
default: "auto",
|
|
39
|
+
description: "Content moderation level",
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
google: {
|
|
44
|
+
"gemini-2.5-flash-image": {
|
|
45
|
+
aspectRatio: {
|
|
46
|
+
values: ["1:1", "3:4", "4:3", "9:16", "16:9"],
|
|
47
|
+
default: "1:1",
|
|
48
|
+
description: "Image aspect ratio",
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
"gemini-3-pro-image-preview": {
|
|
52
|
+
aspectRatio: {
|
|
53
|
+
values: ["1:1", "3:4", "4:3", "9:16", "16:9"],
|
|
54
|
+
default: "1:1",
|
|
55
|
+
description: "Image aspect ratio",
|
|
56
|
+
},
|
|
57
|
+
imageSize: {
|
|
58
|
+
values: ["1K", "2K"],
|
|
59
|
+
default: "1K",
|
|
60
|
+
description: "Output image size",
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
xai: {},
|
|
65
|
+
};
|
|
66
|
+
export const IMAGE_EDIT_MODEL_SCHEMA = {
|
|
67
|
+
openai: {
|
|
68
|
+
"gpt-image-1.5": {
|
|
69
|
+
size: {
|
|
70
|
+
values: ["1024x1024", "1536x1024", "1024x1536", "auto"],
|
|
71
|
+
default: "auto",
|
|
72
|
+
description: "Output image size",
|
|
73
|
+
},
|
|
74
|
+
quality: {
|
|
75
|
+
values: ["low", "medium", "high", "auto"],
|
|
76
|
+
default: "auto",
|
|
77
|
+
description: "Image quality level",
|
|
78
|
+
},
|
|
79
|
+
background: {
|
|
80
|
+
values: ["transparent", "opaque", "auto"],
|
|
81
|
+
default: "auto",
|
|
82
|
+
description: "Background type",
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
google: {
|
|
87
|
+
"gemini-3-pro-image-preview": {},
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
export function getModelConfig(provider, model) {
|
|
91
|
+
return IMAGE_MODEL_SCHEMA[provider]?.[model] || null;
|
|
92
|
+
}
|
|
93
|
+
export function getDefaultConfig(provider, model) {
|
|
94
|
+
const schema = getModelConfig(provider, model);
|
|
95
|
+
if (!schema)
|
|
96
|
+
return {};
|
|
97
|
+
const defaults = {};
|
|
98
|
+
for (const [key, option] of Object.entries(schema)) {
|
|
99
|
+
defaults[key] = option.default;
|
|
100
|
+
}
|
|
101
|
+
return defaults;
|
|
102
|
+
}
|
|
103
|
+
//# sourceMappingURL=image-model-schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"image-model-schema.js","sourceRoot":"","sources":["../src/image-model-schema.ts"],"names":[],"mappings":"AAkBA,MAAM,CAAC,MAAM,kBAAkB,GAAqB;IAClD,MAAM,EAAE;QACN,UAAU,EAAE;YACV,IAAI,EAAE;gBACJ,MAAM,EAAE,CAAC,WAAW,EAAE,WAAW,EAAE,WAAW,CAAC;gBAC/C,OAAO,EAAE,WAAW;gBACpB,WAAW,EAAE,kBAAkB;aAChC;YACD,OAAO,EAAE;gBACP,MAAM,EAAE,CAAC,UAAU,EAAE,IAAI,CAAC;gBAC1B,OAAO,EAAE,UAAU;gBACnB,WAAW,EAAE,qBAAqB;aACnC;YACD,KAAK,EAAE;gBACL,MAAM,EAAE,CAAC,OAAO,EAAE,SAAS,CAAC;gBAC5B,OAAO,EAAE,OAAO;gB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