openloops 0.1.39 → 0.2.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/README.md +40 -4
- package/dist/clients/index.d.ts +2 -2
- package/dist/clients/index.js +4 -4
- package/dist/clients/index.mjs +2 -2
- package/dist/clients/llm/index.d.ts +1 -0
- package/dist/{loops/plan-execute → clients/llm}/index.js +4 -4
- package/dist/clients/llm/index.mjs +1 -0
- package/dist/clients/{llm-client.d.ts → llm/llm-client.d.ts} +3 -14
- package/dist/clients/{llm-client.js → llm/llm-client.js} +14 -37
- package/dist/clients/{llm-client.mjs → llm/llm-client.mjs} +15 -38
- package/dist/clients/{llm-error.mjs → llm/llm-error.mjs} +1 -1
- package/dist/clients/{llm-types.d.ts → llm/llm-types.d.ts} +1 -1
- package/dist/clients/llm/model-resolution.d.ts +20 -0
- package/dist/clients/llm/model-resolution.js +83 -0
- package/dist/clients/llm/model-resolution.mjs +46 -0
- package/dist/clients/{pi-ai-adapter.mjs → llm/pi-ai-adapter.mjs} +1 -1
- package/dist/clients/serper/index.d.ts +1 -0
- package/dist/clients/serper/index.js +22 -0
- package/dist/clients/serper/index.mjs +1 -0
- package/dist/clients/{serper-client.js → serper/serper-client.js} +2 -2
- package/dist/clients/{serper-client.mjs → serper/serper-client.mjs} +3 -3
- package/dist/harness/agent-loop.d.ts +0 -1
- package/dist/harness/agent.d.ts +6 -1
- package/dist/harness/agent.js +21 -13
- package/dist/harness/agent.mjs +21 -13
- package/dist/harness/native-tools.d.ts +1 -1
- package/dist/{loops/shared → harness}/skills/approval-request.d.ts +1 -1
- package/dist/{loops/shared → harness}/skills/approval-request.js +1 -1
- package/dist/{loops/shared → harness}/skills/approval-request.mjs +2 -2
- package/dist/{loops/shared → harness}/skills/autonomous-answer.d.ts +1 -1
- package/dist/{loops/shared → harness}/skills/autonomous-answer.js +1 -1
- package/dist/{loops/shared → harness}/skills/autonomous-answer.mjs +2 -2
- package/dist/{loops/shared → harness}/skills/confirmation-gate.d.ts +1 -1
- package/dist/{loops/shared → harness}/skills/confirmation-gate.js +1 -1
- package/dist/{loops/shared → harness}/skills/confirmation-gate.mjs +2 -2
- package/dist/harness/skills/index.d.ts +4 -0
- package/dist/{loops/plan-execute → harness}/skills/index.js +8 -8
- package/dist/harness/skills/index.mjs +4 -0
- package/dist/{loops/shared → harness}/skills/mcp-change-review.d.ts +1 -1
- package/dist/{loops/shared → harness}/skills/mcp-change-review.js +1 -1
- package/dist/{loops/shared → harness}/skills/mcp-change-review.mjs +2 -2
- package/dist/harness/tool-catalog.d.ts +1 -1
- package/dist/loops/index.d.ts +0 -1
- package/dist/loops/index.js +0 -2
- package/dist/loops/index.mjs +0 -1
- package/dist/loops/shared/skills/index.d.ts +0 -4
- package/dist/loops/shared/skills/index.js +1 -9
- package/dist/loops/shared/skills/index.mjs +0 -4
- package/dist/services/chats/entities/chat.entity.d.ts +0 -5
- package/dist/services/chats/entities/chat.entity.js +0 -10
- package/dist/services/chats/entities/chat.entity.mjs +0 -10
- package/dist/services/llmcalls/module.d.ts +4 -2
- package/dist/services/llmcalls/module.js +13 -6
- package/dist/services/llmcalls/module.mjs +11 -5
- package/dist/services/llmcalls/use-cases/get-llm-usage-by-chat.use-case.d.ts +14 -0
- package/dist/services/llmcalls/use-cases/get-llm-usage-by-chat.use-case.js +62 -0
- package/dist/services/llmcalls/use-cases/get-llm-usage-by-chat.use-case.mjs +33 -0
- package/dist/services/llmcalls/use-cases/get-llm-usage-by-message.use-case.d.ts +14 -0
- package/dist/services/llmcalls/use-cases/{get-llm-usage.use-case.js → get-llm-usage-by-message.use-case.js} +18 -37
- package/dist/services/llmcalls/use-cases/get-llm-usage-by-message.use-case.mjs +33 -0
- package/dist/services/llmcalls/utils/usage-totals.d.ts +20 -0
- package/dist/services/llmcalls/utils/usage-totals.js +31 -0
- package/dist/services/llmcalls/utils/usage-totals.mjs +29 -0
- package/dist/services/tasks/entities/agent-task.entity.d.ts +2 -24
- package/dist/services/tasks/entities/agent-task.entity.js +2 -75
- package/dist/services/tasks/entities/agent-task.entity.mjs +2 -75
- package/dist/services/users/entities/user-default-model.d.ts +11 -0
- package/dist/services/users/entities/user-default-model.js +42 -0
- package/dist/services/users/entities/user-default-model.mjs +19 -0
- package/dist/services/users/entities/user-preferences.d.ts +4 -1
- package/dist/services/users/entities/user-preferences.js +8 -3
- package/dist/services/users/entities/user-preferences.mjs +8 -3
- package/dist/services/users/use-cases/create-user.use-case.js +3 -1
- package/dist/services/users/use-cases/create-user.use-case.mjs +3 -1
- package/dist/services/users/use-cases/update-user.use-case.js +4 -1
- package/dist/services/users/use-cases/update-user.use-case.mjs +4 -1
- package/dist/services/users/utils/default-model.d.ts +6 -0
- package/dist/services/users/utils/default-model.js +38 -0
- package/dist/services/users/utils/default-model.mjs +15 -0
- package/dist/skills/call-modes.d.ts +1 -1
- package/dist/skills/skill.d.ts +1 -1
- package/dist/skills/skill.js +1 -1
- package/dist/skills/skill.mjs +1 -1
- package/dist/tools/core/web-search/web-search.tool.js +1 -1
- package/dist/tools/core/web-search/web-search.tool.mjs +1 -1
- package/docs/README.md +1 -1
- package/docs/agent.md +4 -3
- package/docs/agentic-jobs.md +1 -1
- package/docs/assets/harness-car.svg +79 -0
- package/docs/chats.md +1 -1
- package/docs/configuration.md +18 -4
- package/docs/harness.md +12 -1
- package/docs/integration-guide.md +2 -2
- package/docs/llms.txt +1 -1
- package/docs/loops.md +4 -15
- package/docs/usage.md +19 -14
- package/docs/users.md +23 -0
- package/examples/run-agent/run-agent-with-fallback-model.ts +25 -0
- package/examples/usage/get-chat-usage.ts +8 -10
- package/examples/usage/get-message-usage.ts +5 -7
- package/examples/users/set-default-model.ts +36 -0
- package/package.json +1 -4
- package/dist/loops/plan-execute/index.d.ts +0 -1
- package/dist/loops/plan-execute/index.mjs +0 -1
- package/dist/loops/plan-execute/loop.d.ts +0 -26
- package/dist/loops/plan-execute/loop.js +0 -267
- package/dist/loops/plan-execute/loop.mjs +0 -249
- package/dist/loops/plan-execute/skills/action-planner.d.ts +0 -35
- package/dist/loops/plan-execute/skills/action-planner.js +0 -71
- package/dist/loops/plan-execute/skills/action-planner.mjs +0 -48
- package/dist/loops/plan-execute/skills/final-responder.d.ts +0 -7
- package/dist/loops/plan-execute/skills/final-responder.js +0 -58
- package/dist/loops/plan-execute/skills/final-responder.mjs +0 -35
- package/dist/loops/plan-execute/skills/index.d.ts +0 -4
- package/dist/loops/plan-execute/skills/index.mjs +0 -4
- package/dist/loops/plan-execute/skills/state-observer.d.ts +0 -10
- package/dist/loops/plan-execute/skills/state-observer.js +0 -61
- package/dist/loops/plan-execute/skills/state-observer.mjs +0 -38
- package/dist/loops/plan-execute/skills/strategy-engine.d.ts +0 -11
- package/dist/loops/plan-execute/skills/strategy-engine.js +0 -61
- package/dist/loops/plan-execute/skills/strategy-engine.mjs +0 -38
- package/dist/services/llmcalls/use-cases/get-llm-usage.use-case.d.ts +0 -24
- package/dist/services/llmcalls/use-cases/get-llm-usage.use-case.mjs +0 -51
- package/dist/skills/skill-runner.d.ts +0 -30
- package/dist/skills/skill-runner.js +0 -121
- package/dist/skills/skill-runner.mjs +0 -92
- /package/dist/clients/{llm-error.d.ts → llm/llm-error.d.ts} +0 -0
- /package/dist/clients/{llm-error.js → llm/llm-error.js} +0 -0
- /package/dist/clients/{llm-types.js → llm/llm-types.js} +0 -0
- /package/dist/clients/{llm-types.mjs → llm/llm-types.mjs} +0 -0
- /package/dist/clients/{pi-ai-adapter.d.ts → llm/pi-ai-adapter.d.ts} +0 -0
- /package/dist/clients/{pi-ai-adapter.js → llm/pi-ai-adapter.js} +0 -0
- /package/dist/clients/{serper-client.d.ts → serper/serper-client.d.ts} +0 -0
|
@@ -43,7 +43,7 @@ const STEP_REF_GLOBAL = new RegExp(`\\{\\{step_([\\w-]+)\\.output${PATH}\\}\\}`,
|
|
|
43
43
|
const CONTEXT_REF = new RegExp(`^\\{\\{context\\.([\\w-]+)${PATH}\\}\\}$`);
|
|
44
44
|
const CONTEXT_REF_GLOBAL = new RegExp(`\\{\\{context\\.([\\w-]+)${PATH}\\}\\}`, "g");
|
|
45
45
|
const LEFTOVER_REF = /\{\{\s*(?:step_|context\.)/;
|
|
46
|
-
const CLEARABLE_FIELDS = ["nextNode"
|
|
46
|
+
const CLEARABLE_FIELDS = ["nextNode"];
|
|
47
47
|
function normalizeToolName(name) {
|
|
48
48
|
return name.toLowerCase().replace(/-/g, "_");
|
|
49
49
|
}
|
|
@@ -156,21 +156,6 @@ function readPath(value, path) {
|
|
|
156
156
|
}
|
|
157
157
|
return current;
|
|
158
158
|
}
|
|
159
|
-
function scopeStepRefs(value, scope) {
|
|
160
|
-
if (typeof value === "string") {
|
|
161
|
-
return value.replace(/\{\{step_([\w-]+)(?=\.output)/g, (match, id) => {
|
|
162
|
-
const scoped = scope(id);
|
|
163
|
-
return scoped ? `{{step_${scoped}` : match;
|
|
164
|
-
});
|
|
165
|
-
}
|
|
166
|
-
if (Array.isArray(value)) return value.map((item) => scopeStepRefs(item, scope));
|
|
167
|
-
if (value !== null && typeof value === "object") {
|
|
168
|
-
const scoped = {};
|
|
169
|
-
for (const key of Object.keys(value)) scoped[key] = scopeStepRefs(value[key], scope);
|
|
170
|
-
return scoped;
|
|
171
|
-
}
|
|
172
|
-
return value;
|
|
173
|
-
}
|
|
174
159
|
function collectRefs(value, found = { steps: [], contexts: [] }) {
|
|
175
160
|
if (typeof value === "string") {
|
|
176
161
|
for (const match of value.matchAll(STEP_REF_GLOBAL)) found.steps.push(match[1]);
|
|
@@ -187,7 +172,7 @@ function collectRefs(value, found = { steps: [], contexts: [] }) {
|
|
|
187
172
|
return found;
|
|
188
173
|
}
|
|
189
174
|
class AgentTask extends BaseEntity {
|
|
190
|
-
constructor(props, chatId, status, goal, nextNode, threadId, previousTaskId, summary, loopName,
|
|
175
|
+
constructor(props, chatId, status, goal, nextNode, threadId, previousTaskId, summary, loopName, opening, turns = [], known, schemas) {
|
|
191
176
|
super(props);
|
|
192
177
|
this.props = props;
|
|
193
178
|
this.chatId = chatId;
|
|
@@ -198,10 +183,6 @@ class AgentTask extends BaseEntity {
|
|
|
198
183
|
this.previousTaskId = previousTaskId;
|
|
199
184
|
this.summary = summary;
|
|
200
185
|
this.loopName = loopName;
|
|
201
|
-
this.planCount = planCount;
|
|
202
|
-
this.planOffset = planOffset;
|
|
203
|
-
this.executedOffset = executedOffset;
|
|
204
|
-
this.scratch = scratch;
|
|
205
186
|
this.opening = opening;
|
|
206
187
|
this.turns = turns;
|
|
207
188
|
this.known = known;
|
|
@@ -216,10 +197,6 @@ class AgentTask extends BaseEntity {
|
|
|
216
197
|
previousTaskId;
|
|
217
198
|
summary;
|
|
218
199
|
loopName;
|
|
219
|
-
planCount;
|
|
220
|
-
planOffset;
|
|
221
|
-
executedOffset;
|
|
222
|
-
scratch;
|
|
223
200
|
opening;
|
|
224
201
|
turns;
|
|
225
202
|
known;
|
|
@@ -243,10 +220,6 @@ class AgentTask extends BaseEntity {
|
|
|
243
220
|
props.previousTaskId,
|
|
244
221
|
props.summary,
|
|
245
222
|
props.loopName,
|
|
246
|
-
props.planCount ?? 0,
|
|
247
|
-
props.planOffset ?? 0,
|
|
248
|
-
props.executedOffset ?? 0,
|
|
249
|
-
props.scratch,
|
|
250
223
|
props.opening,
|
|
251
224
|
props.turns ?? [],
|
|
252
225
|
props.known,
|
|
@@ -269,10 +242,6 @@ class AgentTask extends BaseEntity {
|
|
|
269
242
|
previousTaskId: this.previousTaskId,
|
|
270
243
|
summary: this.summary,
|
|
271
244
|
loopName: this.loopName,
|
|
272
|
-
planCount: this.planCount || void 0,
|
|
273
|
-
planOffset: this.planOffset || void 0,
|
|
274
|
-
executedOffset: this.executedOffset || void 0,
|
|
275
|
-
scratch: this.scratch,
|
|
276
245
|
opening: this.opening,
|
|
277
246
|
turns: this.turns.length ? this.turns : void 0,
|
|
278
247
|
known: this.known && Object.keys(this.known).length ? this.known : void 0,
|
|
@@ -292,18 +261,6 @@ class AgentTask extends BaseEntity {
|
|
|
292
261
|
this.actions = actions;
|
|
293
262
|
this.hydrated = true;
|
|
294
263
|
}
|
|
295
|
-
setScratch(key, value) {
|
|
296
|
-
this.scratch = { ...this.scratch, [key]: value };
|
|
297
|
-
}
|
|
298
|
-
getScratch(key) {
|
|
299
|
-
return this.scratch?.[key];
|
|
300
|
-
}
|
|
301
|
-
clearScratch(key) {
|
|
302
|
-
if (!this.scratch || !(key in this.scratch)) return;
|
|
303
|
-
const rest = { ...this.scratch };
|
|
304
|
-
delete rest[key];
|
|
305
|
-
this.scratch = Object.keys(rest).length ? rest : void 0;
|
|
306
|
-
}
|
|
307
264
|
addAction(descriptor) {
|
|
308
265
|
const action = AgentAction.factory({
|
|
309
266
|
chatId: this.chatId,
|
|
@@ -321,22 +278,6 @@ class AgentTask extends BaseEntity {
|
|
|
321
278
|
this.actions.push(action);
|
|
322
279
|
return action;
|
|
323
280
|
}
|
|
324
|
-
addPlan(steps, author) {
|
|
325
|
-
this.skipPending();
|
|
326
|
-
this.planCount += 1;
|
|
327
|
-
const generation = this.planCount;
|
|
328
|
-
const localIds = new Set(steps.map((step) => String(step.stepId)));
|
|
329
|
-
const scopedId = (id) => `${generation}_${id}`;
|
|
330
|
-
const scope = (id) => localIds.has(id) ? scopedId(id) : void 0;
|
|
331
|
-
return steps.map((step) => this.addAction({
|
|
332
|
-
name: step.name,
|
|
333
|
-
stepId: scopedId(step.stepId),
|
|
334
|
-
args: scopeStepRefs(step.args, scope),
|
|
335
|
-
dependsOn: step.dependsOn?.map(String).map((id) => scope(id) ?? id),
|
|
336
|
-
reasoning: step.reasoning,
|
|
337
|
-
author
|
|
338
|
-
}));
|
|
339
|
-
}
|
|
340
281
|
skipPending() {
|
|
341
282
|
const pending = this.actions.filter((a) => a.status === "pending");
|
|
342
283
|
pending.forEach((a) => a.markSkipped());
|
|
@@ -562,12 +503,6 @@ class AgentTask extends BaseEntity {
|
|
|
562
503
|
get executedActions() {
|
|
563
504
|
return this.actions.filter((a) => a.isTerminal);
|
|
564
505
|
}
|
|
565
|
-
get replanCount() {
|
|
566
|
-
return Math.max(0, this.planCount - this.planOffset - 1);
|
|
567
|
-
}
|
|
568
|
-
get executedSinceOpen() {
|
|
569
|
-
return Math.max(0, this.executedActions.length - this.executedOffset);
|
|
570
|
-
}
|
|
571
506
|
get lastExecutedAction() {
|
|
572
507
|
return this.actions.slice().reverse().find((a) => a.isTerminal);
|
|
573
508
|
}
|
|
@@ -595,14 +530,6 @@ class AgentTask extends BaseEntity {
|
|
|
595
530
|
this.status = "paused" /* PAUSED */;
|
|
596
531
|
}
|
|
597
532
|
}
|
|
598
|
-
reopen() {
|
|
599
|
-
this.status = "in_progress" /* IN_PROGRESS */;
|
|
600
|
-
this.nextNode = void 0;
|
|
601
|
-
this.planOffset = this.planCount;
|
|
602
|
-
this.executedOffset = this.executedActions.length;
|
|
603
|
-
this.clearScratch("replan_feedback");
|
|
604
|
-
this.clearScratch("stop_reason");
|
|
605
|
-
}
|
|
606
533
|
findActionByRef(ref) {
|
|
607
534
|
return this.actions.find((a) => a.stepId === ref || a.id === ref);
|
|
608
535
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export interface DefaultModelProps {
|
|
2
|
+
provider?: string;
|
|
3
|
+
model?: string;
|
|
4
|
+
}
|
|
5
|
+
export declare class DefaultModel {
|
|
6
|
+
provider?: string | undefined;
|
|
7
|
+
model?: string | undefined;
|
|
8
|
+
constructor(provider?: string | undefined, model?: string | undefined);
|
|
9
|
+
static fromJSON(props: DefaultModelProps): DefaultModel;
|
|
10
|
+
toJSON(): DefaultModelProps;
|
|
11
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var user_default_model_exports = {};
|
|
20
|
+
__export(user_default_model_exports, {
|
|
21
|
+
DefaultModel: () => DefaultModel
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(user_default_model_exports);
|
|
24
|
+
var import_helpers = require("../../../common/helpers/index.js");
|
|
25
|
+
class DefaultModel {
|
|
26
|
+
constructor(provider, model) {
|
|
27
|
+
this.provider = provider;
|
|
28
|
+
this.model = model;
|
|
29
|
+
}
|
|
30
|
+
provider;
|
|
31
|
+
model;
|
|
32
|
+
static fromJSON(props) {
|
|
33
|
+
return new DefaultModel((0, import_helpers.sanitizeString)(props.provider), (0, import_helpers.sanitizeString)(props.model));
|
|
34
|
+
}
|
|
35
|
+
toJSON() {
|
|
36
|
+
return { provider: this.provider, model: this.model };
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
40
|
+
0 && (module.exports = {
|
|
41
|
+
DefaultModel
|
|
42
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import "../../../chunk-CF3WOMB3.mjs";
|
|
2
|
+
import { sanitizeString } from "../../../common/helpers/index.js";
|
|
3
|
+
class DefaultModel {
|
|
4
|
+
constructor(provider, model) {
|
|
5
|
+
this.provider = provider;
|
|
6
|
+
this.model = model;
|
|
7
|
+
}
|
|
8
|
+
provider;
|
|
9
|
+
model;
|
|
10
|
+
static fromJSON(props) {
|
|
11
|
+
return new DefaultModel(sanitizeString(props.provider), sanitizeString(props.model));
|
|
12
|
+
}
|
|
13
|
+
toJSON() {
|
|
14
|
+
return { provider: this.provider, model: this.model };
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export {
|
|
18
|
+
DefaultModel
|
|
19
|
+
};
|
|
@@ -4,6 +4,7 @@ import { Country, CountryProps } from './user-country';
|
|
|
4
4
|
import { Currency, CurrencyProps } from './user-currency';
|
|
5
5
|
import { Timezone, TimezoneProps } from './user-timezone';
|
|
6
6
|
import { Language, LanguageProps } from './user-language';
|
|
7
|
+
import { DefaultModel, DefaultModelProps } from './user-default-model';
|
|
7
8
|
export interface UserPreferencesProps {
|
|
8
9
|
notifications?: NotificationPreferencesProps;
|
|
9
10
|
reports?: ReportPreferencesProps;
|
|
@@ -11,6 +12,7 @@ export interface UserPreferencesProps {
|
|
|
11
12
|
currency?: CurrencyProps;
|
|
12
13
|
timezone?: TimezoneProps;
|
|
13
14
|
language?: LanguageProps;
|
|
15
|
+
defaultModel?: DefaultModelProps;
|
|
14
16
|
}
|
|
15
17
|
export declare class UserPreferences {
|
|
16
18
|
notifications?: NotificationPreferences | undefined;
|
|
@@ -19,7 +21,8 @@ export declare class UserPreferences {
|
|
|
19
21
|
currency?: Currency | undefined;
|
|
20
22
|
timezone?: Timezone | undefined;
|
|
21
23
|
language?: Language | undefined;
|
|
22
|
-
|
|
24
|
+
defaultModel?: DefaultModel | undefined;
|
|
25
|
+
constructor(notifications?: NotificationPreferences | undefined, reports?: ReportPreferences | undefined, country?: Country | undefined, currency?: Currency | undefined, timezone?: Timezone | undefined, language?: Language | undefined, defaultModel?: DefaultModel | undefined);
|
|
23
26
|
static fromJSON(props: UserPreferencesProps): UserPreferences;
|
|
24
27
|
toJSON(): UserPreferencesProps;
|
|
25
28
|
}
|
|
@@ -27,14 +27,16 @@ var import_user_country = require("./user-country");
|
|
|
27
27
|
var import_user_currency = require("./user-currency");
|
|
28
28
|
var import_user_timezone = require("./user-timezone");
|
|
29
29
|
var import_user_language = require("./user-language");
|
|
30
|
+
var import_user_default_model = require("./user-default-model");
|
|
30
31
|
class UserPreferences {
|
|
31
|
-
constructor(notifications, reports, country, currency, timezone, language) {
|
|
32
|
+
constructor(notifications, reports, country, currency, timezone, language, defaultModel) {
|
|
32
33
|
this.notifications = notifications;
|
|
33
34
|
this.reports = reports;
|
|
34
35
|
this.country = country;
|
|
35
36
|
this.currency = currency;
|
|
36
37
|
this.timezone = timezone;
|
|
37
38
|
this.language = language;
|
|
39
|
+
this.defaultModel = defaultModel;
|
|
38
40
|
}
|
|
39
41
|
notifications;
|
|
40
42
|
reports;
|
|
@@ -42,6 +44,7 @@ class UserPreferences {
|
|
|
42
44
|
currency;
|
|
43
45
|
timezone;
|
|
44
46
|
language;
|
|
47
|
+
defaultModel;
|
|
45
48
|
static fromJSON(props) {
|
|
46
49
|
return new UserPreferences(
|
|
47
50
|
props.notifications && import_user_notification_preferences.NotificationPreferences.fromJSON(props.notifications),
|
|
@@ -49,7 +52,8 @@ class UserPreferences {
|
|
|
49
52
|
props.country && import_user_country.Country.fromJSON(props.country),
|
|
50
53
|
props.currency && import_user_currency.Currency.fromJSON(props.currency),
|
|
51
54
|
props.timezone && import_user_timezone.Timezone.fromJSON(props.timezone),
|
|
52
|
-
props.language && import_user_language.Language.fromJSON(props.language)
|
|
55
|
+
props.language && import_user_language.Language.fromJSON(props.language),
|
|
56
|
+
props.defaultModel && import_user_default_model.DefaultModel.fromJSON(props.defaultModel)
|
|
53
57
|
);
|
|
54
58
|
}
|
|
55
59
|
toJSON() {
|
|
@@ -59,7 +63,8 @@ class UserPreferences {
|
|
|
59
63
|
country: this.country?.toJSON(),
|
|
60
64
|
currency: this.currency?.toJSON(),
|
|
61
65
|
timezone: this.timezone?.toJSON(),
|
|
62
|
-
language: this.language?.toJSON()
|
|
66
|
+
language: this.language?.toJSON(),
|
|
67
|
+
defaultModel: this.defaultModel?.toJSON()
|
|
63
68
|
};
|
|
64
69
|
}
|
|
65
70
|
}
|
|
@@ -5,14 +5,16 @@ import { Country } from "./user-country";
|
|
|
5
5
|
import { Currency } from "./user-currency";
|
|
6
6
|
import { Timezone } from "./user-timezone";
|
|
7
7
|
import { Language } from "./user-language";
|
|
8
|
+
import { DefaultModel } from "./user-default-model";
|
|
8
9
|
class UserPreferences {
|
|
9
|
-
constructor(notifications, reports, country, currency, timezone, language) {
|
|
10
|
+
constructor(notifications, reports, country, currency, timezone, language, defaultModel) {
|
|
10
11
|
this.notifications = notifications;
|
|
11
12
|
this.reports = reports;
|
|
12
13
|
this.country = country;
|
|
13
14
|
this.currency = currency;
|
|
14
15
|
this.timezone = timezone;
|
|
15
16
|
this.language = language;
|
|
17
|
+
this.defaultModel = defaultModel;
|
|
16
18
|
}
|
|
17
19
|
notifications;
|
|
18
20
|
reports;
|
|
@@ -20,6 +22,7 @@ class UserPreferences {
|
|
|
20
22
|
currency;
|
|
21
23
|
timezone;
|
|
22
24
|
language;
|
|
25
|
+
defaultModel;
|
|
23
26
|
static fromJSON(props) {
|
|
24
27
|
return new UserPreferences(
|
|
25
28
|
props.notifications && NotificationPreferences.fromJSON(props.notifications),
|
|
@@ -27,7 +30,8 @@ class UserPreferences {
|
|
|
27
30
|
props.country && Country.fromJSON(props.country),
|
|
28
31
|
props.currency && Currency.fromJSON(props.currency),
|
|
29
32
|
props.timezone && Timezone.fromJSON(props.timezone),
|
|
30
|
-
props.language && Language.fromJSON(props.language)
|
|
33
|
+
props.language && Language.fromJSON(props.language),
|
|
34
|
+
props.defaultModel && DefaultModel.fromJSON(props.defaultModel)
|
|
31
35
|
);
|
|
32
36
|
}
|
|
33
37
|
toJSON() {
|
|
@@ -37,7 +41,8 @@ class UserPreferences {
|
|
|
37
41
|
country: this.country?.toJSON(),
|
|
38
42
|
currency: this.currency?.toJSON(),
|
|
39
43
|
timezone: this.timezone?.toJSON(),
|
|
40
|
-
language: this.language?.toJSON()
|
|
44
|
+
language: this.language?.toJSON(),
|
|
45
|
+
defaultModel: this.defaultModel?.toJSON()
|
|
41
46
|
};
|
|
42
47
|
}
|
|
43
48
|
}
|
|
@@ -34,6 +34,7 @@ var import_tsyringe = require("tsyringe");
|
|
|
34
34
|
var import_base = require("../../../common/base/base.use-case.js");
|
|
35
35
|
var import_repositories = require("../repositories");
|
|
36
36
|
var import_entities = require("../entities");
|
|
37
|
+
var import_default_model = require("../utils/default-model");
|
|
37
38
|
let CreateUserUseCase = class extends import_base.BaseUseCase {
|
|
38
39
|
constructor(userRepository) {
|
|
39
40
|
super();
|
|
@@ -44,7 +45,8 @@ let CreateUserUseCase = class extends import_base.BaseUseCase {
|
|
|
44
45
|
const { payload, currentUser } = params;
|
|
45
46
|
if (!payload?.email) throw new Error("[Create User] email param is required");
|
|
46
47
|
if (!payload?.password) throw new Error("[Create User] password param is required");
|
|
47
|
-
const
|
|
48
|
+
const model = payload.preferences ? await (0, import_default_model.readDefaultModel)(payload.preferences) : void 0;
|
|
49
|
+
const user = await import_entities.User.create({ ...payload, ...payload.preferences ? { preferences: model.preferences } : {} });
|
|
48
50
|
user.setCreatedBy(currentUser);
|
|
49
51
|
await this.userRepository?.create(user);
|
|
50
52
|
const { password, ...rest } = user.toJSON();
|
|
@@ -6,6 +6,7 @@ import { autoInjectable, inject } from "tsyringe";
|
|
|
6
6
|
import { BaseUseCase } from "../../../common/base/base.use-case.js";
|
|
7
7
|
import { UserRepository } from "../repositories";
|
|
8
8
|
import { User } from "../entities";
|
|
9
|
+
import { readDefaultModel } from "../utils/default-model";
|
|
9
10
|
let CreateUserUseCase = class extends BaseUseCase {
|
|
10
11
|
constructor(userRepository) {
|
|
11
12
|
super();
|
|
@@ -16,7 +17,8 @@ let CreateUserUseCase = class extends BaseUseCase {
|
|
|
16
17
|
const { payload, currentUser } = params;
|
|
17
18
|
if (!payload?.email) throw new Error("[Create User] email param is required");
|
|
18
19
|
if (!payload?.password) throw new Error("[Create User] password param is required");
|
|
19
|
-
const
|
|
20
|
+
const model = payload.preferences ? await readDefaultModel(payload.preferences) : void 0;
|
|
21
|
+
const user = await User.create({ ...payload, ...payload.preferences ? { preferences: model.preferences } : {} });
|
|
20
22
|
user.setCreatedBy(currentUser);
|
|
21
23
|
await this.userRepository?.create(user);
|
|
22
24
|
const { password, ...rest } = user.toJSON();
|
|
@@ -34,6 +34,7 @@ var import_tsyringe = require("tsyringe");
|
|
|
34
34
|
var import_base = require("../../../common/base/base.use-case.js");
|
|
35
35
|
var import_repositories = require("../repositories");
|
|
36
36
|
var import_entities = require("../entities");
|
|
37
|
+
var import_default_model = require("../utils/default-model");
|
|
37
38
|
let UpdateUserUseCase = class extends import_base.BaseUseCase {
|
|
38
39
|
constructor(userRepository) {
|
|
39
40
|
super();
|
|
@@ -45,8 +46,10 @@ let UpdateUserUseCase = class extends import_base.BaseUseCase {
|
|
|
45
46
|
if (!payload || Object.keys(payload).length === 0) {
|
|
46
47
|
throw new Error("Payload is required for updating user");
|
|
47
48
|
}
|
|
48
|
-
const
|
|
49
|
+
const model = payload.preferences ? await (0, import_default_model.readDefaultModel)(payload.preferences) : void 0;
|
|
50
|
+
const user = await import_entities.User.create({ ...payload, ...payload.preferences ? { preferences: model.preferences } : {}, _id: id });
|
|
49
51
|
user.setUpdatedBy(currentUser);
|
|
52
|
+
if (model?.clear) user.unset(["preferences.defaultModel"]);
|
|
50
53
|
this.logger.info(`Updating user: ${user.stringify()}`);
|
|
51
54
|
const result = await this.userRepository?.update(user);
|
|
52
55
|
if (!result) {
|
|
@@ -6,6 +6,7 @@ import { autoInjectable, inject } from "tsyringe";
|
|
|
6
6
|
import { BaseUseCase } from "../../../common/base/base.use-case.js";
|
|
7
7
|
import { UserRepository } from "../repositories";
|
|
8
8
|
import { User } from "../entities";
|
|
9
|
+
import { readDefaultModel } from "../utils/default-model";
|
|
9
10
|
let UpdateUserUseCase = class extends BaseUseCase {
|
|
10
11
|
constructor(userRepository) {
|
|
11
12
|
super();
|
|
@@ -17,8 +18,10 @@ let UpdateUserUseCase = class extends BaseUseCase {
|
|
|
17
18
|
if (!payload || Object.keys(payload).length === 0) {
|
|
18
19
|
throw new Error("Payload is required for updating user");
|
|
19
20
|
}
|
|
20
|
-
const
|
|
21
|
+
const model = payload.preferences ? await readDefaultModel(payload.preferences) : void 0;
|
|
22
|
+
const user = await User.create({ ...payload, ...payload.preferences ? { preferences: model.preferences } : {}, _id: id });
|
|
21
23
|
user.setUpdatedBy(currentUser);
|
|
24
|
+
if (model?.clear) user.unset(["preferences.defaultModel"]);
|
|
22
25
|
this.logger.info(`Updating user: ${user.stringify()}`);
|
|
23
26
|
const result = await this.userRepository?.update(user);
|
|
24
27
|
if (!result) {
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var default_model_exports = {};
|
|
20
|
+
__export(default_model_exports, {
|
|
21
|
+
readDefaultModel: () => readDefaultModel
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(default_model_exports);
|
|
24
|
+
var import_model_resolution = require("../../../clients/llm/model-resolution.js");
|
|
25
|
+
async function readDefaultModel(preferences) {
|
|
26
|
+
const requested = preferences?.defaultModel;
|
|
27
|
+
if (requested === void 0) return { preferences, clear: false };
|
|
28
|
+
const { defaultModel, ...rest } = preferences;
|
|
29
|
+
if (requested === null) return { preferences: rest, clear: true };
|
|
30
|
+
const ref = (0, import_model_resolution.toModelRef)(requested);
|
|
31
|
+
if (!ref) throw new Error("The default model needs a provider and a model, or null to remove it");
|
|
32
|
+
if (!await (0, import_model_resolution.isKnownModel)(ref.provider, ref.model)) throw new Error(`The model "${ref.provider}/${ref.model}" does not exist`);
|
|
33
|
+
return { preferences: { ...rest, defaultModel: { provider: ref.provider, model: ref.model } }, clear: false };
|
|
34
|
+
}
|
|
35
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
36
|
+
0 && (module.exports = {
|
|
37
|
+
readDefaultModel
|
|
38
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import "../../../chunk-CF3WOMB3.mjs";
|
|
2
|
+
import { isKnownModel, toModelRef } from "../../../clients/llm/model-resolution.js";
|
|
3
|
+
async function readDefaultModel(preferences) {
|
|
4
|
+
const requested = preferences?.defaultModel;
|
|
5
|
+
if (requested === void 0) return { preferences, clear: false };
|
|
6
|
+
const { defaultModel, ...rest } = preferences;
|
|
7
|
+
if (requested === null) return { preferences: rest, clear: true };
|
|
8
|
+
const ref = toModelRef(requested);
|
|
9
|
+
if (!ref) throw new Error("The default model needs a provider and a model, or null to remove it");
|
|
10
|
+
if (!await isKnownModel(ref.provider, ref.model)) throw new Error(`The model "${ref.provider}/${ref.model}" does not exist`);
|
|
11
|
+
return { preferences: { ...rest, defaultModel: { provider: ref.provider, model: ref.model } }, clear: false };
|
|
12
|
+
}
|
|
13
|
+
export {
|
|
14
|
+
readDefaultModel
|
|
15
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { LLMMessage, LLMResponse, LLMToolChoice, LLMToolDefinition } from '../clients/llm-types.js';
|
|
1
|
+
import type { LLMMessage, LLMResponse, LLMToolChoice, LLMToolDefinition } from '../clients/llm/llm-types.js';
|
|
2
2
|
export type SkillMode = 'plain_chat' | 'function_calling' | 'function_calling_split' | 'legacy_tools_off';
|
|
3
3
|
export declare const DEFAULT_SKILL_MODE: SkillMode;
|
|
4
4
|
export declare const SKILL_MODES: SkillMode[];
|
package/dist/skills/skill.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { LLMMessage, LLMToolDefinition } from '../clients/llm-types.js';
|
|
1
|
+
import { LLMMessage, LLMToolDefinition } from '../clients/llm/llm-types.js';
|
|
2
2
|
import { CurrentUser, CurrentSession } from '../common/base/index.js';
|
|
3
3
|
import type { Chat } from '../services/chats/entities/chat.entity.js';
|
|
4
4
|
import { SkillMode } from './call-modes';
|
package/dist/skills/skill.js
CHANGED
|
@@ -25,7 +25,7 @@ __export(skill_exports, {
|
|
|
25
25
|
module.exports = __toCommonJS(skill_exports);
|
|
26
26
|
var import_tsyringe = require("tsyringe");
|
|
27
27
|
var import_helpers = require("../common/helpers/index.js");
|
|
28
|
-
var import_llm_client = require("../clients/llm-client.js");
|
|
28
|
+
var import_llm_client = require("../clients/llm/llm-client.js");
|
|
29
29
|
var import_logger = require("../common/logger/index.js");
|
|
30
30
|
var import_runtime_context = require("./runtime-context");
|
|
31
31
|
var import_call_modes = require("./call-modes");
|
package/dist/skills/skill.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import "../chunk-CF3WOMB3.mjs";
|
|
2
2
|
import { container } from "tsyringe";
|
|
3
3
|
import { extractJSON } from "../common/helpers/index.js";
|
|
4
|
-
import { LLMClient } from "../clients/llm-client.js";
|
|
4
|
+
import { LLMClient } from "../clients/llm/llm-client.js";
|
|
5
5
|
import { Logger } from "../common/logger/index.js";
|
|
6
6
|
import { buildRuntimeContext } from "./runtime-context";
|
|
7
7
|
import { DEFAULT_SKILL_MODE, buildModeCall, readModeResponse } from "./call-modes";
|
|
@@ -22,7 +22,7 @@ __export(web_search_tool_exports, {
|
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(web_search_tool_exports);
|
|
24
24
|
var import_tool = require("../../tool");
|
|
25
|
-
var import_serper_client = require("../../../clients/serper-client.js");
|
|
25
|
+
var import_serper_client = require("../../../clients/serper/serper-client.js");
|
|
26
26
|
const webSearchTool = new import_tool.Tool({
|
|
27
27
|
name: "web_search",
|
|
28
28
|
description: "Search on web",
|
|
@@ -2,7 +2,7 @@ import "../../../chunk-CF3WOMB3.mjs";
|
|
|
2
2
|
import { Tool } from "../../tool";
|
|
3
3
|
import {
|
|
4
4
|
SerperClient
|
|
5
|
-
} from "../../../clients/serper-client.js";
|
|
5
|
+
} from "../../../clients/serper/serper-client.js";
|
|
6
6
|
const webSearchTool = new Tool({
|
|
7
7
|
name: "web_search",
|
|
8
8
|
description: "Search on web",
|
package/docs/README.md
CHANGED
|
@@ -12,7 +12,7 @@ Start with the [README](../README.md) for what `openloops` is and how to run it.
|
|
|
12
12
|
|
|
13
13
|
| Page | What it covers |
|
|
14
14
|
| --- | --- |
|
|
15
|
-
| [The `Agent`
|
|
15
|
+
| [The `Agent`](agent.md) | Options, running a turn, the result and its statuses, confirmations, autonomous mode, hooks and interruption. |
|
|
16
16
|
| [Configuration](configuration.md) | Environment variables, choosing the model and what is recorded. |
|
|
17
17
|
| [Agentic jobs](agentic-jobs.md) | Tasks that the agent runs by itself on a schedule: recurrence, the history of runs and the runner that executes them. |
|
|
18
18
|
| [Chats](chats.md) | The chat record, its messages and their `source`, listing, reading and deleting chats. |
|
package/docs/agent.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
# The `Agent`
|
|
1
|
+
# The `Agent`
|
|
2
2
|
|
|
3
|
-
`Agent` is the
|
|
3
|
+
`Agent` is the entry point of the [harness](harness.md), and it drives an `AgentLoop`. It owns everything a loop shouldn't have to think about: loading and saving the chat, dispatching to the right node, running guardrails, resolving tools (native and MCP), asking for confirmation, handling interruption requests, and tracking usage.
|
|
4
4
|
|
|
5
5
|
```typescript
|
|
6
6
|
import { Agent } from 'openloops/core'
|
|
@@ -33,6 +33,7 @@ const agent = new Agent({
|
|
|
33
33
|
| `identity` | no | none | Name, gender and role injected into every skill. |
|
|
34
34
|
| `maxInputLength` | no | `100000` | Longest message accepted, in characters. Longer messages are blocked by a built-in guard. |
|
|
35
35
|
| `maxIterations` | no | `50` | Hard limit of loop iterations in one run. When reached, the run fails with `AGENT_MAX_ITERATIONS_REACHED`. |
|
|
36
|
+
| `fallbackModel` | no | none | `{ provider, model }` used when neither the run, the chat nor the user chose a model. See [configuration](configuration.md#which-model-a-chat-uses). |
|
|
36
37
|
| `strictMode` | no | `false` | When `true`, the user is always asked before the agent uses an MCP server whose tools changed after being approved. See [MCP servers](mcp-servers.md#how-the-agent-uses-the-servers). |
|
|
37
38
|
|
|
38
39
|
An `Agent` instance holds the state of the run it is executing, so run one conversation at a time per instance and create another instance for concurrent runs.
|
|
@@ -61,7 +62,7 @@ Omit `chatId` to start a brand-new chat. Pass an existing `chatId` to continue a
|
|
|
61
62
|
|
|
62
63
|
| Option | What it does |
|
|
63
64
|
| --- | --- |
|
|
64
|
-
| `modelProvider`, `modelName` | Model
|
|
65
|
+
| `modelProvider`, `modelName` | Model for this run, always together. It is saved in the chat and used by the next runs that do not send one. Without it, the model comes from the chat, the preference of the user and the fallbacks. See [configuration](configuration.md#which-model-a-chat-uses). |
|
|
65
66
|
| `loopName` | Name of the loop driving the chat. Set automatically from the loop. |
|
|
66
67
|
| `executionMode` | `interactive` (default) or `autonomous`. See [Autonomous mode](#autonomous-mode). |
|
|
67
68
|
| `notifyOnCompletion` | Exposed as `agent.notifyOnCompletion` so a post execution hook can notify the user. |
|
package/docs/agentic-jobs.md
CHANGED
|
@@ -43,7 +43,7 @@ result.data.nextRunAt
|
|
|
43
43
|
| `recurrence` | yes | When it runs. See below. |
|
|
44
44
|
| `timezone` | yes | An IANA timezone. The local time of the recurrence and the days are those of this timezone, and daylight saving time is respected. |
|
|
45
45
|
| `enabled` | no | `true` by default. A job that is off never runs, and can be turned on again. |
|
|
46
|
-
| `modelProvider`, `modelName` | no | The model of the job, both or none. Without them the default model is used. |
|
|
46
|
+
| `modelProvider`, `modelName` | no | The model of the job, both or none. Without them, the default model of the owner is used, then the fallbacks. See [configuration](configuration.md#which-model-a-chat-uses). |
|
|
47
47
|
|
|
48
48
|
`nextRunAt` is calculated when the job is created and it is what you show to the user. The fields that the system manages (`nextRunAt`, `lastRunAt`, `lastRunStatus`, `lockedBy`, `lockedUntil`, `activeRunId`) are ignored if they come in the payload.
|
|
49
49
|
|