nolo-cli 0.1.10 → 0.1.12
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 +0 -32
- package/agentRuntimeCommands.ts +1 -1
- package/client/compactDialog.ts +2 -5
- package/commandRegistry.ts +2 -2
- package/machineCommands.ts +28 -3
- package/package.json +5 -25
- package/ai/agent/_executeModel.ts +0 -118
- package/ai/agent/agentSlice.ts +0 -525
- package/ai/agent/appWorkingMemory.ts +0 -126
- package/ai/agent/avatarUtils.ts +0 -24
- package/ai/agent/buildEditingContext.ts +0 -373
- package/ai/agent/buildSystemPrompt.ts +0 -532
- package/ai/agent/cleanAgentMessages.ts +0 -140
- package/ai/agent/cliChatClient.ts +0 -119
- package/ai/agent/contextCompiler.ts +0 -107
- package/ai/agent/contextLayerContract.ts +0 -44
- package/ai/agent/createAgentSchema.ts +0 -234
- package/ai/agent/executeToolCall.ts +0 -58
- package/ai/agent/fetchAgentContexts.ts +0 -42
- package/ai/agent/generatePrompt.ts +0 -3
- package/ai/agent/getFullChatContextKeys.ts +0 -168
- package/ai/agent/hooks/fetchPublicAgents.ts +0 -133
- package/ai/agent/hooks/useAgentConfig.ts +0 -61
- package/ai/agent/hooks/useAgentDialog.ts +0 -35
- package/ai/agent/hooks/useAgentFormValidation.ts +0 -202
- package/ai/agent/hooks/usePublicAgents.ts +0 -473
- package/ai/agent/persistMessageWithFixedId.ts +0 -37
- package/ai/agent/planSlice.ts +0 -259
- package/ai/agent/referenceUtils.ts +0 -229
- package/ai/agent/runAgentBackground.ts +0 -238
- package/ai/agent/runAgentClientLoop.ts +0 -138
- package/ai/agent/runtimeGuidance.ts +0 -97
- package/ai/agent/runtimeServerBase.ts +0 -37
- package/ai/agent/server/fetchPublicAgents.ts +0 -128
- package/ai/agent/startParallelAgentStreams.ts +0 -424
- package/ai/agent/startupProtocol.ts +0 -53
- package/ai/agent/streamAgentChatTurn.ts +0 -1278
- package/ai/agent/streamAgentChatTurnUtils.ts +0 -738
- package/ai/agent/types.ts +0 -71
- package/ai/agent/utils/imageOutput.ts +0 -33
- package/ai/agent/utils/sortUtils.ts +0 -250
- package/ai/agent/web/referencePickerUtils.ts +0 -146
- package/ai/ai.locale.ts +0 -1079
- package/ai/chat/accumulateToolCallChunks.ts +0 -95
- package/ai/chat/fetchUtils.native.ts +0 -276
- package/ai/chat/fetchUtils.ts +0 -153
- package/ai/chat/parseApiError.ts +0 -64
- package/ai/chat/parseMultilineSSE.ts +0 -95
- package/ai/chat/sendOpenAICompletionsRequest.native.ts +0 -682
- package/ai/chat/sendOpenAICompletionsRequest.ts +0 -703
- package/ai/chat/sendOpenAIResponseRequest.ts +0 -491
- package/ai/chat/shouldUseServerProxy.ts +0 -18
- package/ai/chat/sseClient.native.ts +0 -91
- package/ai/chat/sseClient.ts +0 -67
- package/ai/chat/streamReader.native.ts +0 -31
- package/ai/chat/streamReader.ts +0 -62
- package/ai/chat/updateTotalUsage.ts +0 -72
- package/ai/context/buildReferenceContext.ts +0 -437
- package/ai/context/calculateContextUsage.ts +0 -133
- package/ai/context/retention.ts +0 -165
- package/ai/context/tokenUtils.ts +0 -78
- package/ai/index.ts +0 -1
- package/ai/llm/calculateGeminiImageTokens.ts +0 -57
- package/ai/llm/deepinfra.ts +0 -28
- package/ai/llm/fireworks.ts +0 -50
- package/ai/llm/generateRequestBody.ts +0 -165
- package/ai/llm/getModelContextWindow.ts +0 -84
- package/ai/llm/getNoloKey.ts +0 -31
- package/ai/llm/getPricing.ts +0 -199
- package/ai/llm/hooks/useModelPricing.ts +0 -75
- package/ai/llm/imagePricing.ts +0 -40
- package/ai/llm/isResponseAPIModel.ts +0 -13
- package/ai/llm/mimo.ts +0 -71
- package/ai/llm/mistral.ts +0 -22
- package/ai/llm/modelAvatar.ts +0 -427
- package/ai/llm/models.ts +0 -45
- package/ai/llm/openrouterModels.ts +0 -269
- package/ai/llm/providers.ts +0 -306
- package/ai/llm/reasoningModels.ts +0 -28
- package/ai/llm/types.ts +0 -59
- package/ai/llm/usageRequestOptions.ts +0 -59
- package/ai/memory/capture.ts +0 -148
- package/ai/memory/consolidate.ts +0 -104
- package/ai/memory/delete.ts +0 -147
- package/ai/memory/overlay.ts +0 -84
- package/ai/memory/query.ts +0 -38
- package/ai/memory/queryShared.ts +0 -160
- package/ai/memory/rank.ts +0 -105
- package/ai/memory/recentRelationshipRecap.ts +0 -249
- package/ai/memory/remember.ts +0 -167
- package/ai/memory/runtime.ts +0 -76
- package/ai/memory/store.ts +0 -20
- package/ai/memory/storeShared.ts +0 -76
- package/ai/memory/types.ts +0 -46
- package/ai/memory/understanding.ts +0 -349
- package/ai/memory/understandingGreeting.ts +0 -264
- package/ai/messages/type.ts +0 -20
- package/ai/policy/personalizationDialog.ts +0 -333
- package/ai/policy/runtimePolicy.ts +0 -440
- package/ai/policy/selfUpdateFields.ts +0 -48
- package/ai/policy/types.ts +0 -64
- package/ai/skills/referenceRuntime.ts +0 -274
- package/ai/skills/skillDiagnostics.ts +0 -251
- package/ai/skills/skillDocBuilder.ts +0 -139
- package/ai/skills/skillDocProtocol.ts +0 -434
- package/ai/skills/skillReferenceSummary.ts +0 -63
- package/ai/skills/skillSummaryMarker.ts +0 -26
- package/ai/token/calculatePrice.ts +0 -544
- package/ai/token/db.ts +0 -98
- package/ai/token/externalToolCost.ts +0 -330
- package/ai/token/hooks/useRecords.ts +0 -65
- package/ai/token/missingUsageEstimate.ts +0 -42
- package/ai/token/modelUsageQuery.ts +0 -252
- package/ai/token/normalizeUsage.ts +0 -84
- package/ai/token/openaiImageGenerationUsage.ts +0 -56
- package/ai/token/prepareTokenUsageData.ts +0 -88
- package/ai/token/query.ts +0 -88
- package/ai/token/queryUserTokens.ts +0 -59
- package/ai/token/resolveBillingTarget.ts +0 -52
- package/ai/token/saveTokenRecord.ts +0 -53
- package/ai/token/serverDialogProjection.ts +0 -78
- package/ai/token/serverTokenWriter.ts +0 -143
- package/ai/token/stats.ts +0 -21
- package/ai/token/tokenThunks.ts +0 -24
- package/ai/token/types.ts +0 -93
- package/ai/tools/agent/agentTools.ts +0 -176
- package/ai/tools/agent/agentUpdateShared.ts +0 -311
- package/ai/tools/agent/callAgentTool.ts +0 -139
- package/ai/tools/agent/createAgentTool.ts +0 -512
- package/ai/tools/agent/createDialogTool.ts +0 -69
- package/ai/tools/agent/createSkillAgentTool.ts +0 -62
- package/ai/tools/agent/parallelBudget.ts +0 -221
- package/ai/tools/agent/presets/appBuilderPreset.ts +0 -145
- package/ai/tools/agent/runLlmTool.ts +0 -96
- package/ai/tools/agent/runStreamingAgentTool.ts +0 -73
- package/ai/tools/agent/skillAgentArgs.ts +0 -106
- package/ai/tools/agent/skillAgentPreset.ts +0 -89
- package/ai/tools/agent/streamParallelAgentsTool.ts +0 -122
- package/ai/tools/agent/updateAgentTool.ts +0 -96
- package/ai/tools/agent/updateSelfTool.ts +0 -113
- package/ai/tools/amazonProductScraperTool.ts +0 -86
- package/ai/tools/apifyActorClient.ts +0 -45
- package/ai/tools/appEditGuard.ts +0 -372
- package/ai/tools/appReadSnapshot.ts +0 -153
- package/ai/tools/appTools.ts +0 -1549
- package/ai/tools/applyEditTool.ts +0 -256
- package/ai/tools/applyLineEditsTool.ts +0 -312
- package/ai/tools/browserTools/click.ts +0 -33
- package/ai/tools/browserTools/closeSession.ts +0 -29
- package/ai/tools/browserTools/common.ts +0 -27
- package/ai/tools/browserTools/openSession.ts +0 -48
- package/ai/tools/browserTools/readContent.ts +0 -38
- package/ai/tools/browserTools/selectOption.ts +0 -46
- package/ai/tools/browserTools/typeText.ts +0 -42
- package/ai/tools/category/createCategoryTool.ts +0 -66
- package/ai/tools/category/queryContentsByCategoryTool.ts +0 -69
- package/ai/tools/category/updateContentCategoryTool.ts +0 -75
- package/ai/tools/cfBrowserTools.ts +0 -319
- package/ai/tools/cfSpeechToTextTool.ts +0 -49
- package/ai/tools/checkEnvTool.ts +0 -65
- package/ai/tools/cloudflareCrawlTool.ts +0 -289
- package/ai/tools/codeSearchTool.ts +0 -111
- package/ai/tools/codeTools.ts +0 -101
- package/ai/tools/createDocTool.ts +0 -132
- package/ai/tools/createPlanTool.ts +0 -999
- package/ai/tools/createSkillDocTool.ts +0 -155
- package/ai/tools/createWorkflowTool.ts +0 -154
- package/ai/tools/deepseekOcrTool.ts +0 -34
- package/ai/tools/delayTool.ts +0 -31
- package/ai/tools/deleteSpacesTool.ts +0 -325
- package/ai/tools/deleteSpacesToolModel.ts +0 -159
- package/ai/tools/devReloadUtils.ts +0 -29
- package/ai/tools/dialogMessageSearch.ts +0 -137
- package/ai/tools/doctorSkillTool.ts +0 -72
- package/ai/tools/ecommerceScraperTool.ts +0 -86
- package/ai/tools/emailTools.ts +0 -549
- package/ai/tools/evalSkillTool.ts +0 -92
- package/ai/tools/exaSearchTool.ts +0 -64
- package/ai/tools/execBashTool.ts +0 -379
- package/ai/tools/executeSqlTool.ts +0 -192
- package/ai/tools/fetchWebpageSupport.ts +0 -309
- package/ai/tools/fetchWebpageTool.ts +0 -84
- package/ai/tools/geminiImagePreviewTool.ts +0 -361
- package/ai/tools/generateDocxTool.ts +0 -215
- package/ai/tools/googleSearchScraperTool.ts +0 -106
- package/ai/tools/importDataTool.ts +0 -133
- package/ai/tools/importSkillTool.ts +0 -162
- package/ai/tools/index.ts +0 -1858
- package/ai/tools/listFilesTool.ts +0 -82
- package/ai/tools/listUserSpacesTool.ts +0 -113
- package/ai/tools/modelUsageTools.ts +0 -142
- package/ai/tools/olmOcrTool.ts +0 -34
- package/ai/tools/openaiImageTool.ts +0 -218
- package/ai/tools/paddleOcrTool.ts +0 -34
- package/ai/tools/prepareTools.ts +0 -23
- package/ai/tools/readDocTool.ts +0 -84
- package/ai/tools/readFileTool.ts +0 -211
- package/ai/tools/readTool.ts +0 -163
- package/ai/tools/readXPostTool.ts +0 -233
- package/ai/tools/rememberMemoryTool.ts +0 -84
- package/ai/tools/remotionVideoTool.ts +0 -151
- package/ai/tools/searchDialogMessagesTool.ts +0 -222
- package/ai/tools/searchRepoTool.ts +0 -115
- package/ai/tools/searchWorkspaceTool.ts +0 -259
- package/ai/tools/skillFollowup.ts +0 -86
- package/ai/tools/surfWeatherTool.ts +0 -169
- package/ai/tools/table/addTableRowTool.ts +0 -217
- package/ai/tools/table/createTableTool.ts +0 -315
- package/ai/tools/table/rowTools.ts +0 -366
- package/ai/tools/table/schemaTools.ts +0 -244
- package/ai/tools/table/shareTableTool.ts +0 -148
- package/ai/tools/table/toolShared.ts +0 -129
- package/ai/tools/toolApiClient.ts +0 -198
- package/ai/tools/toolNameAliases.ts +0 -57
- package/ai/tools/toolResultError.ts +0 -42
- package/ai/tools/toolRunSlice.ts +0 -303
- package/ai/tools/toolSchemaCompatibility.ts +0 -53
- package/ai/tools/toolVisibility.ts +0 -4
- package/ai/tools/types.ts +0 -20
- package/ai/tools/uiAskChoiceTool.ts +0 -104
- package/ai/tools/updateContentTitleTool.ts +0 -84
- package/ai/tools/updateDocTool.ts +0 -105
- package/ai/tools/updateUserPreferenceProfileTool.ts +0 -145
- package/ai/tools/whisperTool.ts +0 -77
- package/ai/tools/writeFileTool.ts +0 -210
- package/ai/tools/youtubeScraperTool.ts +0 -116
- package/ai/tools/ziweiChartTool.ts +0 -678
- package/ai/types.ts +0 -55
- package/ai/workflow/workflowExecutor.ts +0 -323
- package/ai/workflow/workflowSlice.ts +0 -73
- package/ai/workflow/workflowTypes.ts +0 -106
- package/connector-experimental/index.ts +0 -5
package/README.md
CHANGED
|
@@ -171,35 +171,3 @@ Future product-direction examples for the broader TUI command model:
|
|
|
171
171
|
|
|
172
172
|
See [`docs/nolo-cli-tui.md`](../../docs/nolo-cli-tui.md) for the product and
|
|
173
173
|
technical direction.
|
|
174
|
-
|
|
175
|
-
## Building for Publish
|
|
176
|
-
|
|
177
|
-
The CLI is developed in a monorepo with workspace dependencies (`ai` and
|
|
178
|
-
`connector-experimental`). To generate a publish-safe package that can be
|
|
179
|
-
installed via npm outside the monorepo:
|
|
180
|
-
|
|
181
|
-
```bash
|
|
182
|
-
bun run build:publish
|
|
183
|
-
```
|
|
184
|
-
|
|
185
|
-
This creates a `dist/` directory with:
|
|
186
|
-
- All source files from the `files` array in package.json
|
|
187
|
-
- Inlined workspace dependencies (copied as nested directories)
|
|
188
|
-
- A modified package.json with workspace dependencies stripped
|
|
189
|
-
|
|
190
|
-
The `dist/` directory can be published to npm:
|
|
191
|
-
|
|
192
|
-
```bash
|
|
193
|
-
cd dist
|
|
194
|
-
npm publish
|
|
195
|
-
```
|
|
196
|
-
|
|
197
|
-
Key differences between repo-local and published versions:
|
|
198
|
-
- **Repo-local**: Runs from source (`packages/cli/index.ts`) with workspace
|
|
199
|
-
dependencies resolved by the monorepo
|
|
200
|
-
- **Published**: Runs from dist (`dist/index.ts`) with workspace dependencies
|
|
201
|
-
inlined as nested directories
|
|
202
|
-
|
|
203
|
-
Both versions use the same Bun runtime and TypeScript source files. The build
|
|
204
|
-
process does not transpile; it only restructures the package for standalone use.
|
|
205
|
-
|
package/agentRuntimeCommands.ts
CHANGED
|
@@ -56,7 +56,7 @@ function readOption(args: string[], flag: string) {
|
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
async function defaultExecuteCli(provider: string, prompt: string, options: { model?: string; yolo?: boolean }) {
|
|
59
|
-
const { executeCli } = await import("ai/agent/cliExecutor");
|
|
59
|
+
const { executeCli } = await import("./ai/agent/cliExecutor");
|
|
60
60
|
return executeCli(provider as any, prompt, options);
|
|
61
61
|
}
|
|
62
62
|
|
package/client/compactDialog.ts
CHANGED
|
@@ -8,13 +8,10 @@ const DB_PATH = "/api/v1/db";
|
|
|
8
8
|
/**
|
|
9
9
|
* Extract userId from a JWT-style auth token without verifying the signature.
|
|
10
10
|
* Mirrors the logic of `parseToken` in `auth/token.ts` without the crypto imports.
|
|
11
|
-
* @internal - exported for testing only
|
|
12
11
|
*/
|
|
13
|
-
|
|
12
|
+
function parseTokenUserId(token: string): string | null {
|
|
14
13
|
try {
|
|
15
|
-
const
|
|
16
|
-
if (parts.length < 2) return null;
|
|
17
|
-
const payloadBase64 = parts[1];
|
|
14
|
+
const [payloadBase64] = token.split(".");
|
|
18
15
|
const payload = JSON.parse(
|
|
19
16
|
Buffer.from(payloadBase64, "base64").toString("utf8")
|
|
20
17
|
);
|
package/commandRegistry.ts
CHANGED
|
@@ -77,8 +77,8 @@ export function renderHelpText() {
|
|
|
77
77
|
" nolo connect",
|
|
78
78
|
" nolo connect --watch",
|
|
79
79
|
" nolo connect --ws",
|
|
80
|
-
" nolo connect --
|
|
81
|
-
" nolo daemon --server-url https://api.nolo.chat --api-key sk_machine_xxx",
|
|
80
|
+
" nolo connect --ws --server-url https://api.nolo.chat --api-key sk_machine_xxx",
|
|
81
|
+
" nolo connect --daemon --server-url https://api.nolo.chat --api-key sk_machine_xxx",
|
|
82
82
|
" nolo machine status",
|
|
83
83
|
" nolo doctor",
|
|
84
84
|
" nolo update",
|
package/machineCommands.ts
CHANGED
|
@@ -74,6 +74,31 @@ function hasFlag(args: string[], flag: string) {
|
|
|
74
74
|
return args.includes(flag);
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
+
function readOption(args: string[], flag: string) {
|
|
78
|
+
for (let i = 0; i < args.length; i++) {
|
|
79
|
+
const arg = args[i];
|
|
80
|
+
if (arg === flag) {
|
|
81
|
+
const next = args[i + 1];
|
|
82
|
+
if (typeof next === "string" && !next.startsWith("-")) return next;
|
|
83
|
+
return "";
|
|
84
|
+
}
|
|
85
|
+
if (arg.startsWith(flag + "=")) {
|
|
86
|
+
return arg.slice(flag.length + 1);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return "";
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function resolveConnectServerUrl(args: string[], env: EnvLike) {
|
|
93
|
+
const fromFlag = readOption(args, "--server-url") || readOption(args, "--server");
|
|
94
|
+
const raw = fromFlag || env.NOLO_SERVER || env.BASE_URL || DEFAULT_NOLO_SERVER_URL;
|
|
95
|
+
return String(raw).replace(/\/+$|\s+$/g, "").replace(/\/+$/g, "").replace(/\s+$/g, "");
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function resolveConnectAuthToken(args: string[], env: EnvLike) {
|
|
99
|
+
return readOption(args, "--api-key") || readOption(args, "--token") || resolveAuthToken(env);
|
|
100
|
+
}
|
|
101
|
+
|
|
77
102
|
function resolveDaemonLogPath(env: EnvLike) {
|
|
78
103
|
return env.NOLO_CONNECT_LOG || join(homedir(), ".nolo", "logs", "connector.log");
|
|
79
104
|
}
|
|
@@ -136,7 +161,7 @@ async function defaultConnectWebSocket(url: string, options: ConnectorWebSocketO
|
|
|
136
161
|
}
|
|
137
162
|
|
|
138
163
|
async function defaultExecuteCli(provider: string, prompt: string, options: { model?: string; yolo?: boolean }) {
|
|
139
|
-
const { executeCli } = await import("ai/agent/cliExecutor");
|
|
164
|
+
const { executeCli } = await import("./ai/agent/cliExecutor");
|
|
140
165
|
return executeCli(provider as any, prompt, options);
|
|
141
166
|
}
|
|
142
167
|
|
|
@@ -223,13 +248,13 @@ export async function runMachineConnectCommand(
|
|
|
223
248
|
) {
|
|
224
249
|
const env = deps.env ?? process.env;
|
|
225
250
|
const output = deps.output ?? process.stdout;
|
|
226
|
-
const authToken =
|
|
251
|
+
const authToken = resolveConnectAuthToken(args, env);
|
|
227
252
|
if (!authToken) {
|
|
228
253
|
writeAuthMissing(output);
|
|
229
254
|
return 1;
|
|
230
255
|
}
|
|
231
256
|
|
|
232
|
-
const serverUrl =
|
|
257
|
+
const serverUrl = resolveConnectServerUrl(args, env);
|
|
233
258
|
const fetchImpl = deps.fetchImpl ?? fetch;
|
|
234
259
|
const machine = (deps.machineInfo ?? detectLaunchableMachineInfo)();
|
|
235
260
|
const sendHeartbeat = async () => {
|
package/package.json
CHANGED
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nolo-cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.12",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Agent-first terminal workspace for Nolo",
|
|
6
6
|
"bin": {
|
|
7
7
|
"nolo": "index.ts"
|
|
8
8
|
},
|
|
9
9
|
"module": "index.ts",
|
|
10
|
-
"scripts": {
|
|
11
|
-
"build:publish": "bun build.ts"
|
|
12
|
-
},
|
|
13
10
|
"files": [
|
|
14
11
|
"index.ts",
|
|
15
12
|
"agentRuntimeCommands.ts",
|
|
@@ -19,11 +16,8 @@
|
|
|
19
16
|
"defaultServer.ts",
|
|
20
17
|
"machineCommands.ts",
|
|
21
18
|
"updateCommands.ts",
|
|
22
|
-
"client
|
|
23
|
-
"
|
|
24
|
-
"client/profileConfig.ts",
|
|
25
|
-
"tui/readlineWorkspace.ts",
|
|
26
|
-
"tui/session.ts",
|
|
19
|
+
"client/**/*.ts",
|
|
20
|
+
"tui/**/*.ts",
|
|
27
21
|
"README.md",
|
|
28
22
|
"ai/**/*.ts",
|
|
29
23
|
"connector-experimental/**/*.ts"
|
|
@@ -31,24 +25,10 @@
|
|
|
31
25
|
"publishConfig": {
|
|
32
26
|
"access": "public"
|
|
33
27
|
},
|
|
34
|
-
"
|
|
35
|
-
"
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"ulid": "^2.3.0"
|
|
36
30
|
},
|
|
37
31
|
"peerDependencies": {
|
|
38
32
|
"typescript": "^5.0.0"
|
|
39
|
-
},
|
|
40
|
-
"dependencies": {
|
|
41
|
-
"@reduxjs/toolkit": "^2.5.0",
|
|
42
|
-
"iztro": "^2.5.8",
|
|
43
|
-
"ulid": "^2.3.0",
|
|
44
|
-
"pino": "^9.9.0",
|
|
45
|
-
"react": "^19.2.1",
|
|
46
|
-
"i18next": "^23.11.5",
|
|
47
|
-
"zod": "^3.25.20",
|
|
48
|
-
"react-hook-form": "^7.51.5",
|
|
49
|
-
"@hookform/resolvers": "^3.3.2",
|
|
50
|
-
"react-i18next": "^14.1.2",
|
|
51
|
-
"react-hot-toast": "^2.4.1",
|
|
52
|
-
"react-native-sse": "^1.2.1"
|
|
53
33
|
}
|
|
54
34
|
}
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
import { RootState } from "app/store";
|
|
2
|
-
import { Agent, Message } from "app/types";
|
|
3
|
-
import { selectCurrentDialogConfig } from "chat/dialog/dialogSlice";
|
|
4
|
-
import { read } from "database/dbSlice";
|
|
5
|
-
import { fetchAgentContexts } from "ai/agent/fetchAgentContexts";
|
|
6
|
-
import { filterAndCleanMessages } from "integrations/openai/filterAndCleanMessages";
|
|
7
|
-
import { selectAllMsgs } from "chat/messages/messageSlice";
|
|
8
|
-
import { generateRequestBody } from "ai/llm/generateRequestBody";
|
|
9
|
-
import { getApiEndpoint } from "ai/llm/providers";
|
|
10
|
-
import { selectCurrentServer } from "app/settings/settingSlice";
|
|
11
|
-
import { selectCurrentToken } from "auth/authSlice";
|
|
12
|
-
|
|
13
|
-
import { sendOpenAICompletionsRequest } from "../chat/sendOpenAICompletionsRequest";
|
|
14
|
-
import { performFetchRequest } from "../chat/fetchUtils";
|
|
15
|
-
import { updateTokensAction } from "chat/dialog/actions/updateTokensAction";
|
|
16
|
-
import { extractCustomId } from "core/prefix";
|
|
17
|
-
|
|
18
|
-
export const _executeModel = async (
|
|
19
|
-
options: {
|
|
20
|
-
isStreaming: boolean;
|
|
21
|
-
withAgentContext: boolean;
|
|
22
|
-
withChatHistory: boolean;
|
|
23
|
-
agentConfigOverrides?: Record<string, any>;
|
|
24
|
-
},
|
|
25
|
-
args: {
|
|
26
|
-
llmConfig?: Partial<Agent> & Pick<Agent, "provider" | "model">;
|
|
27
|
-
agentKey?: string;
|
|
28
|
-
agentConfig?: Partial<Agent> & Pick<Agent, "provider" | "model">;
|
|
29
|
-
content: any;
|
|
30
|
-
parentMessageId?: string;
|
|
31
|
-
billingDialogKey?: string;
|
|
32
|
-
},
|
|
33
|
-
thunkApi: any
|
|
34
|
-
) => {
|
|
35
|
-
const { isStreaming, withAgentContext, withChatHistory, agentConfigOverrides } = options;
|
|
36
|
-
const { getState, dispatch, rejectWithValue } = thunkApi;
|
|
37
|
-
const { content } = args;
|
|
38
|
-
const state = getState() as RootState;
|
|
39
|
-
|
|
40
|
-
let agentConfig: Partial<Agent> & Pick<Agent, "provider" | "model">;
|
|
41
|
-
if (args.llmConfig) {
|
|
42
|
-
agentConfig = args.llmConfig;
|
|
43
|
-
} else if (args.agentConfig) {
|
|
44
|
-
agentConfig = args.agentConfig;
|
|
45
|
-
} else {
|
|
46
|
-
const agentKey = args.agentKey || selectCurrentDialogConfig(state)?.cybots?.[0];
|
|
47
|
-
if (!agentKey) {
|
|
48
|
-
const msg = "Model execution failed: No llmConfig, agentConfig, or agentKey provided.";
|
|
49
|
-
console.error(msg);
|
|
50
|
-
return rejectWithValue(msg);
|
|
51
|
-
}
|
|
52
|
-
try {
|
|
53
|
-
agentConfig = await dispatch(read({ dbKey: agentKey })).unwrap();
|
|
54
|
-
} catch (error: any) {
|
|
55
|
-
console.error(`_executeModel failed to load agent [${agentKey}]`, error);
|
|
56
|
-
return rejectWithValue(error.message);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
try {
|
|
61
|
-
const resolvedConfig = agentConfigOverrides
|
|
62
|
-
? { ...agentConfig, ...agentConfigOverrides }
|
|
63
|
-
: agentConfig;
|
|
64
|
-
const agentContexts = withAgentContext
|
|
65
|
-
? await fetchAgentContexts(resolvedConfig.references, dispatch)
|
|
66
|
-
: {};
|
|
67
|
-
|
|
68
|
-
let messages: Message[];
|
|
69
|
-
if (withChatHistory) {
|
|
70
|
-
messages = filterAndCleanMessages(selectAllMsgs(state));
|
|
71
|
-
messages.push({ role: "user", content: args.content });
|
|
72
|
-
} else {
|
|
73
|
-
messages = [{ role: "user", content: args.content }];
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
const bodyData = generateRequestBody({
|
|
77
|
-
agentConfig: resolvedConfig,
|
|
78
|
-
messages,
|
|
79
|
-
userInput: content,
|
|
80
|
-
contexts: agentContexts,
|
|
81
|
-
});
|
|
82
|
-
bodyData.stream = isStreaming;
|
|
83
|
-
|
|
84
|
-
if (isStreaming) {
|
|
85
|
-
await sendOpenAICompletionsRequest({
|
|
86
|
-
bodyData,
|
|
87
|
-
agentConfig: resolvedConfig,
|
|
88
|
-
thunkApi,
|
|
89
|
-
dialogKey: selectCurrentDialogConfig(state)?.dbKey,
|
|
90
|
-
parentMessageId: args.parentMessageId,
|
|
91
|
-
});
|
|
92
|
-
} else {
|
|
93
|
-
const response = await performFetchRequest({
|
|
94
|
-
agentConfig: resolvedConfig,
|
|
95
|
-
api: getApiEndpoint(resolvedConfig),
|
|
96
|
-
bodyData,
|
|
97
|
-
currentServer: selectCurrentServer(state),
|
|
98
|
-
token: selectCurrentToken(state),
|
|
99
|
-
});
|
|
100
|
-
const result = await response.json();
|
|
101
|
-
if (args.billingDialogKey && result?.usage) {
|
|
102
|
-
await updateTokensAction(
|
|
103
|
-
{
|
|
104
|
-
dialogId: extractCustomId(args.billingDialogKey),
|
|
105
|
-
dialogKey: args.billingDialogKey,
|
|
106
|
-
usage: result.usage,
|
|
107
|
-
agentConfig: resolvedConfig,
|
|
108
|
-
},
|
|
109
|
-
thunkApi
|
|
110
|
-
);
|
|
111
|
-
}
|
|
112
|
-
return result.choices[0].message.content;
|
|
113
|
-
}
|
|
114
|
-
} catch (error: any) {
|
|
115
|
-
console.error(`_executeModel failed`, error);
|
|
116
|
-
return rejectWithValue(error.message);
|
|
117
|
-
}
|
|
118
|
-
};
|