nolo-cli 0.1.32 → 0.1.33
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 -6
- package/agent-runtime/agentRecordConfig.ts +2 -0
- package/agent-runtime/hostAdapter.ts +1 -0
- package/agent-runtime/index.ts +0 -21
- package/agent-runtime/localToolPolicy.ts +6 -13
- package/agent-runtime/localWorkspaceTools.ts +30 -333
- package/agent-runtime/platformChatProvider.ts +1 -4
- package/agent-runtime/runtimeToolPolicy.ts +47 -32
- package/agentAliases.ts +14 -83
- package/agentCommandSupport.ts +3 -6
- package/agentInternalCommandEntries.ts +2 -13
- package/agentListCommands.ts +19 -28
- package/agentMachineCommands.ts +40 -336
- package/agentPullCommand.ts +36 -56
- package/agentRecordCommands.ts +3 -5
- package/agentRecordHelpers.ts +22 -189
- package/agentRunCommand.ts +438 -107
- package/agentRuntimeLocal.ts +0 -10
- package/ai/agent/cliExecutor.ts +19 -323
- package/authCommands.ts +2 -36
- package/cli/agentAliases.ts +14 -83
- package/cli/agentCommandSupport.ts +3 -6
- package/cli/agentInternalCommandEntries.ts +2 -13
- package/cli/agentListCommands.ts +19 -28
- package/cli/agentMachineCommands.ts +40 -336
- package/cli/agentPullCommand.ts +36 -56
- package/cli/agentRecordCommands.ts +3 -5
- package/cli/agentRecordHelpers.ts +22 -189
- package/cli/agentRunCommand.ts +438 -107
- package/cli/agentRuntimeLocal.ts +0 -10
- package/cli/authCommands.ts +2 -36
- package/cli/cliEnvHelpers.ts +21 -162
- package/cli/client/agentRun.ts +853 -57
- package/cli/client/localRuntimeAdapter.ts +22 -159
- package/cli/client/streamingOutput.ts +3 -1
- package/cli/client/taskRunPrompt.ts +24 -7
- package/cli/commandRegistry.ts +2 -3
- package/cli/connectorRunArtifact.ts +10 -34
- package/cli/connectorWebSocketTarget.ts +6 -10
- package/cli/internalCommandEntries.ts +0 -8
- package/cli/localRuntimeDb.ts +2 -39
- package/cli/machineCommands.ts +189 -190
- package/cli/machineDaemonCommands.ts +165 -9
- package/cli/machineHeartbeatCommands.ts +2 -1
- package/cli/machineStatusCommands.ts +13 -5
- package/cli/machineWatchCommands.ts +1 -1
- package/cli/machineWsRunDispatch.ts +14 -48
- package/cli/machineWsSession.ts +0 -2
- package/cli/offlineMarxistsAgentCommand.ts +314 -0
- package/cli/runtimeDoctorCommands.ts +69 -18
- package/cli/scriptCommandEntries.ts +45 -5
- package/cli/tableCommands.ts +133 -33
- package/cli/taskRunCommand.ts +211 -16
- package/cli/tui/session.ts +372 -43
- package/cli/workflowInternalCommandEntries.ts +0 -20
- package/cliEnvHelpers.ts +21 -162
- package/client/agentConfigResolver.test.ts +2 -0
- package/client/agentRun.test.ts +12 -208
- package/client/agentRun.ts +853 -57
- package/client/localRuntimeAdapter.test.ts +9 -168
- package/client/localRuntimeAdapter.ts +22 -159
- package/client/localToolPolicy.test.ts +4 -28
- package/client/streamingOutput.ts +3 -1
- package/client/taskRunPrompt.ts +24 -7
- package/commandRegistry.ts +2 -3
- package/connectorRunArtifact.ts +10 -34
- package/connectorWebSocketTarget.ts +6 -10
- package/database/server/db.ts +34 -15
- package/internalCommandEntries.ts +0 -8
- package/localRuntimeDb.ts +2 -39
- package/machineCommands.ts +189 -190
- package/machineDaemonCommands.ts +165 -9
- package/machineHeartbeatCommands.ts +2 -1
- package/machineStatusCommands.ts +13 -5
- package/machineWatchCommands.ts +1 -1
- package/machineWsRunDispatch.ts +14 -48
- package/machineWsSession.ts +0 -2
- package/offlineMarxistsAgentCommand.ts +314 -0
- package/package.json +49 -193
- package/runtimeDoctorCommands.ts +69 -18
- package/scriptCommandEntries.ts +45 -5
- package/tableCommands.ts +133 -33
- package/taskRunCommand.ts +211 -16
- package/tui/session.ts +372 -43
- package/workflowInternalCommandEntries.ts +0 -20
- package/agent-runtime/dialogStatus.ts +0 -139
- package/agent-runtime/hostRuntimeConfig.ts +0 -86
- package/agentCreateCustomCommands.ts +0 -278
- package/agentDialogsCommands.ts +0 -227
- package/agentDoctorCommands.ts +0 -203
- package/agentRunLocalWorkspace.ts +0 -182
- package/agentRunParsing.ts +0 -298
- package/agentSuperviseCommands.ts +0 -8
- package/agentUnpublishCommands.ts +0 -113
- package/ai/agent/agentRunDialogLineage.ts +0 -56
- package/ai/policy/types.ts +0 -64
- package/ai/skills/skillSummaryMarker.ts +0 -26
- package/app/types.ts +0 -358
- package/build.ts +0 -16
- package/buildPublish.ts +0 -138
- package/buildPublishArtifactAssembly.ts +0 -724
- package/buildPublishImportAnalysis.ts +0 -242
- package/chat/messages/fetchMessages.ts +0 -84
- package/chat/messages/types.ts +0 -185
- package/cli/agentCreateCustomCommands.ts +0 -278
- package/cli/agentDialogsCommands.ts +0 -227
- package/cli/agentDoctorCommands.ts +0 -203
- package/cli/agentRunLocalWorkspace.ts +0 -182
- package/cli/agentRunParsing.ts +0 -298
- package/cli/agentSuperviseCommands.ts +0 -8
- package/cli/agentUnpublishCommands.ts +0 -113
- package/cli/buildPublish.ts +0 -138
- package/cli/buildPublishArtifactAssembly.ts +0 -724
- package/cli/buildPublishImportAnalysis.ts +0 -242
- package/cli/cliIoTypes.ts +0 -3
- package/cli/cliRuntimeDoctorReport.ts +0 -193
- package/cli/client/agentRunInput.ts +0 -10
- package/cli/client/agentRunLocalExecution.ts +0 -124
- package/cli/client/agentRunLocalExecutor.ts +0 -179
- package/cli/client/agentRunRuntimeSelection.ts +0 -145
- package/cli/client/agentRunServerTransport.ts +0 -397
- package/cli/client/agentRunTaskRunRecorder.ts +0 -176
- package/cli/customCodingAgentFlow.ts +0 -208
- package/cli/customCodingAgentRecord.ts +0 -179
- package/cli/dialogDataAccess.ts +0 -186
- package/cli/dialogInternalCommandEntries.ts +0 -11
- package/cli/dialogReadCommands.ts +0 -180
- package/cli/dialogReadHelpers.ts +0 -226
- package/cli/dialogStatusCommands.ts +0 -123
- package/cli/docInternalCommandEntries.ts +0 -20
- package/cli/hybridReadHelpers.ts +0 -109
- package/cli/machineCommandPrompts.ts +0 -79
- package/cli/machineCommandResolution.ts +0 -43
- package/cli/noloReadBridgePrompt.ts +0 -16
- package/cli/pageCreateCommands.ts +0 -219
- package/cli/pageDeleteCommands.ts +0 -167
- package/cli/pageReadCommands.ts +0 -151
- package/cli/pageUpdateCommands.ts +0 -249
- package/cli/pageWriteHelpers.ts +0 -209
- package/cli/publishPackage.ts +0 -36
- package/cli/runtimeInternalCommandEntries.ts +0 -15
- package/cli/runtimePassthroughCommands.ts +0 -22
- package/cli/scriptPassthroughHelpers.ts +0 -28
- package/cli/secretScanHelpers.ts +0 -31
- package/cli/spaceAttachCommands.ts +0 -134
- package/cli/spaceCategoryCommands.ts +0 -263
- package/cli/spaceCommands.ts +0 -295
- package/cli/spaceDeleteCommands.ts +0 -312
- package/cli/spaceInternalCommandEntries.ts +0 -21
- package/cli/spaceMutationHelpers.ts +0 -135
- package/cli/spaceReadCommands.ts +0 -323
- package/cli/tableDataOutput.ts +0 -41
- package/cli/tableDataSafety.ts +0 -26
- package/cli/tableMetaCommands.ts +0 -307
- package/cli/tableMutationCommands.ts +0 -266
- package/cli/tableQueryParsing.ts +0 -90
- package/cli/tableQueryRequest.ts +0 -53
- package/cli/taskRunActions.ts +0 -122
- package/cli/taskRunParsing.ts +0 -86
- package/cli/taskRunPromptShared.ts +0 -55
- package/cli/tui/tuiCatalog.ts +0 -22
- package/cli/tui/tuiCommandInterpreter.ts +0 -253
- package/cli/tui/tuiPresentation.ts +0 -146
- package/cliIoTypes.ts +0 -3
- package/cliRuntimeDoctorReport.ts +0 -193
- package/client/agentRunInput.ts +0 -10
- package/client/agentRunLocalExecution.test.ts +0 -123
- package/client/agentRunLocalExecution.ts +0 -124
- package/client/agentRunLocalExecutor.ts +0 -179
- package/client/agentRunRuntimeSelection.test.ts +0 -159
- package/client/agentRunRuntimeSelection.ts +0 -145
- package/client/agentRunServerTransport.ts +0 -397
- package/client/agentRunTaskRunRecorder.ts +0 -176
- package/connector-experimental/daemonLauncher.ts +0 -223
- package/create/space/spaceKeys.ts +0 -65
- package/create/types.ts +0 -21
- package/customCodingAgentFlow.ts +0 -208
- package/customCodingAgentRecord.ts +0 -179
- package/database/keys.ts +0 -765
- package/database/server/authorityStoreTypes.ts +0 -31
- package/database/server/legacyServerDb.ts +0 -58
- package/database/server/levelAuthorityStore.ts +0 -75
- package/database/server/memoryAuthorityStore.ts +0 -133
- package/database/server/serverStoreFactory.ts +0 -124
- package/database/tombstones.ts +0 -52
- package/database/utils/ulid.ts +0 -1
- package/dialogDataAccess.ts +0 -186
- package/dialogInternalCommandEntries.ts +0 -11
- package/dialogReadCommands.ts +0 -180
- package/dialogReadHelpers.ts +0 -226
- package/dialogStatusCommands.ts +0 -123
- package/docInternalCommandEntries.ts +0 -20
- package/hybridReadHelpers.ts +0 -109
- package/machineCommandPrompts.ts +0 -79
- package/machineCommandResolution.ts +0 -43
- package/noloReadBridgePrompt.ts +0 -16
- package/pageCreateCommands.ts +0 -219
- package/pageDeleteCommands.ts +0 -167
- package/pageReadCommands.ts +0 -151
- package/pageUpdateCommands.ts +0 -249
- package/pageWriteHelpers.ts +0 -209
- package/publishPackage.ts +0 -36
- package/runtimeInternalCommandEntries.ts +0 -15
- package/runtimePassthroughCommands.ts +0 -22
- package/scriptPassthroughHelpers.ts +0 -28
- package/secretScanHelpers.ts +0 -31
- package/share/helpers.ts +0 -302
- package/share/keys.ts +0 -243
- package/share/types.ts +0 -100
- package/spaceAttachCommands.ts +0 -134
- package/spaceCategoryCommands.ts +0 -263
- package/spaceCommands.ts +0 -295
- package/spaceDeleteCommands.ts +0 -312
- package/spaceInternalCommandEntries.ts +0 -21
- package/spaceMutationHelpers.ts +0 -135
- package/spaceReadCommands.ts +0 -323
- package/tableDataOutput.ts +0 -41
- package/tableDataSafety.ts +0 -26
- package/tableMetaCommands.ts +0 -307
- package/tableMutationCommands.ts +0 -266
- package/tableQueryParsing.ts +0 -90
- package/tableQueryRequest.ts +0 -53
- package/taskRunActions.ts +0 -122
- package/taskRunParsing.ts +0 -86
- package/taskRunPromptShared.ts +0 -55
- package/tui/tuiCatalog.ts +0 -22
- package/tui/tuiCommandInterpreter.test.ts +0 -169
- package/tui/tuiCommandInterpreter.ts +0 -253
- package/tui/tuiPresentation.test.ts +0 -154
- package/tui/tuiPresentation.ts +0 -146
|
@@ -1,208 +0,0 @@
|
|
|
1
|
-
export type CodingAgentServerEntry = {
|
|
2
|
-
baseUrl: string;
|
|
3
|
-
userId: string;
|
|
4
|
-
authToken: string;
|
|
5
|
-
};
|
|
6
|
-
|
|
7
|
-
export type CodingAgentWriteResult = {
|
|
8
|
-
privateKey: string;
|
|
9
|
-
contentKey: string;
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
export type CodingAgentVerifyResult = {
|
|
13
|
-
dialogId: string;
|
|
14
|
-
content: string;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export type CodingAgentFlowDeps = {
|
|
18
|
-
ensureAccess: (args: {
|
|
19
|
-
baseUrl: string;
|
|
20
|
-
seed: string;
|
|
21
|
-
username: string;
|
|
22
|
-
locale: string;
|
|
23
|
-
}) => Promise<{ userId: string; authToken: string }>;
|
|
24
|
-
ensureAccessOnBases: (args: {
|
|
25
|
-
baseUrl: string;
|
|
26
|
-
seed: string;
|
|
27
|
-
username: string;
|
|
28
|
-
locale: string;
|
|
29
|
-
}) => Promise<CodingAgentServerEntry[]>;
|
|
30
|
-
upsertAgentRecordOnBases: (args: {
|
|
31
|
-
serverEntries: CodingAgentServerEntry[];
|
|
32
|
-
agentRecord: Record<string, any>;
|
|
33
|
-
}) => Promise<CodingAgentWriteResult[]>;
|
|
34
|
-
attachAgentToSpace: (args: {
|
|
35
|
-
baseUrl: string;
|
|
36
|
-
userId: string;
|
|
37
|
-
authToken: string;
|
|
38
|
-
spaceId: string;
|
|
39
|
-
contentKey: string;
|
|
40
|
-
title: string;
|
|
41
|
-
}) => Promise<void>;
|
|
42
|
-
verifyAgentResponse: (args: {
|
|
43
|
-
baseUrl: string;
|
|
44
|
-
authToken: string;
|
|
45
|
-
agentKey: string;
|
|
46
|
-
prompt: string;
|
|
47
|
-
expected: string;
|
|
48
|
-
maxRounds: number;
|
|
49
|
-
}) => Promise<CodingAgentVerifyResult>;
|
|
50
|
-
resolveTargetSpaceId: (spaceId?: string) => string | undefined;
|
|
51
|
-
now?: () => number;
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
export type CreateCodingAgentFromRecordOptions = {
|
|
55
|
-
baseUrl: string;
|
|
56
|
-
spaceId?: string;
|
|
57
|
-
localCoreBaseUrl?: string;
|
|
58
|
-
seed?: string;
|
|
59
|
-
username?: string;
|
|
60
|
-
locale?: string;
|
|
61
|
-
agentId: string;
|
|
62
|
-
skipVerify?: boolean;
|
|
63
|
-
verifyPrompt?: string;
|
|
64
|
-
expectedResponse?: string;
|
|
65
|
-
verifyRounds?: number;
|
|
66
|
-
syncAllBases?: boolean;
|
|
67
|
-
buildRecord: (args: {
|
|
68
|
-
userId: string;
|
|
69
|
-
now: number;
|
|
70
|
-
agentId: string;
|
|
71
|
-
}) => Record<string, any>;
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
export function normalizeCodingAgentBaseUrl(baseUrl: string): string {
|
|
75
|
-
return baseUrl.replace(/\/+$/, "");
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
export function splitCodingAgentServerEntries(
|
|
79
|
-
serverEntries: CodingAgentServerEntry[],
|
|
80
|
-
attachBaseUrl: string
|
|
81
|
-
) {
|
|
82
|
-
const normalizedAttachBaseUrl = normalizeCodingAgentBaseUrl(attachBaseUrl);
|
|
83
|
-
const runtimeEntries = serverEntries.map((entry) => ({
|
|
84
|
-
...entry,
|
|
85
|
-
baseUrl: normalizeCodingAgentBaseUrl(entry.baseUrl),
|
|
86
|
-
}));
|
|
87
|
-
const attachEntries = runtimeEntries.filter(
|
|
88
|
-
(entry) => entry.baseUrl === normalizedAttachBaseUrl
|
|
89
|
-
);
|
|
90
|
-
|
|
91
|
-
return {
|
|
92
|
-
runtimeEntries,
|
|
93
|
-
attachEntries,
|
|
94
|
-
needsAttachLogin: attachEntries.length === 0,
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
export async function createCodingAgentFromRecord(
|
|
99
|
-
options: CreateCodingAgentFromRecordOptions,
|
|
100
|
-
deps: CodingAgentFlowDeps
|
|
101
|
-
) {
|
|
102
|
-
const {
|
|
103
|
-
baseUrl,
|
|
104
|
-
spaceId,
|
|
105
|
-
localCoreBaseUrl,
|
|
106
|
-
seed = process.env.AGENT_SEED ?? "nolo-platform-demo-account-v1",
|
|
107
|
-
username = process.env.AGENT_USER ?? "platform-demo",
|
|
108
|
-
locale = process.env.AGENT_LOCALE ?? "zh-CN",
|
|
109
|
-
agentId,
|
|
110
|
-
skipVerify = false,
|
|
111
|
-
verifyPrompt = "只回复 OK",
|
|
112
|
-
expectedResponse = "OK",
|
|
113
|
-
verifyRounds = 2,
|
|
114
|
-
syncAllBases = true,
|
|
115
|
-
buildRecord,
|
|
116
|
-
} = options;
|
|
117
|
-
|
|
118
|
-
const attachSpaceId = deps.resolveTargetSpaceId(spaceId);
|
|
119
|
-
const attachBaseUrl = normalizeCodingAgentBaseUrl(localCoreBaseUrl ?? baseUrl);
|
|
120
|
-
const serverEntries = syncAllBases
|
|
121
|
-
? await deps.ensureAccessOnBases({
|
|
122
|
-
baseUrl,
|
|
123
|
-
seed,
|
|
124
|
-
username,
|
|
125
|
-
locale,
|
|
126
|
-
})
|
|
127
|
-
: [
|
|
128
|
-
{
|
|
129
|
-
baseUrl,
|
|
130
|
-
...(await deps.ensureAccess({
|
|
131
|
-
baseUrl,
|
|
132
|
-
seed,
|
|
133
|
-
username,
|
|
134
|
-
locale,
|
|
135
|
-
})),
|
|
136
|
-
},
|
|
137
|
-
];
|
|
138
|
-
const entryPlan = splitCodingAgentServerEntries(serverEntries, attachBaseUrl);
|
|
139
|
-
const attachEntries = entryPlan.needsAttachLogin
|
|
140
|
-
? [
|
|
141
|
-
{
|
|
142
|
-
baseUrl: attachBaseUrl,
|
|
143
|
-
...(await deps.ensureAccess({
|
|
144
|
-
baseUrl: attachBaseUrl,
|
|
145
|
-
seed,
|
|
146
|
-
username,
|
|
147
|
-
locale,
|
|
148
|
-
})),
|
|
149
|
-
},
|
|
150
|
-
]
|
|
151
|
-
: entryPlan.attachEntries;
|
|
152
|
-
const allEntries = [
|
|
153
|
-
...entryPlan.runtimeEntries,
|
|
154
|
-
...attachEntries.filter(
|
|
155
|
-
(attachEntry) =>
|
|
156
|
-
!entryPlan.runtimeEntries.some((runtimeEntry) => runtimeEntry.baseUrl === attachEntry.baseUrl)
|
|
157
|
-
),
|
|
158
|
-
];
|
|
159
|
-
const primaryEntry = allEntries[0];
|
|
160
|
-
const { userId, authToken } = primaryEntry;
|
|
161
|
-
const now = deps.now?.() ?? Date.now();
|
|
162
|
-
const agentRecord = buildRecord({
|
|
163
|
-
userId,
|
|
164
|
-
now,
|
|
165
|
-
agentId,
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
const [{ privateKey, contentKey }] = await deps.upsertAgentRecordOnBases({
|
|
169
|
-
serverEntries: allEntries,
|
|
170
|
-
agentRecord,
|
|
171
|
-
});
|
|
172
|
-
if (attachSpaceId) {
|
|
173
|
-
for (const entry of attachEntries) {
|
|
174
|
-
await deps.attachAgentToSpace({
|
|
175
|
-
baseUrl: entry.baseUrl,
|
|
176
|
-
userId,
|
|
177
|
-
authToken: entry.authToken,
|
|
178
|
-
spaceId: attachSpaceId,
|
|
179
|
-
contentKey,
|
|
180
|
-
title: agentRecord.name ?? agentId,
|
|
181
|
-
});
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
const verify = skipVerify
|
|
186
|
-
? { dialogId: "", content: "SKIPPED" }
|
|
187
|
-
: await deps.verifyAgentResponse({
|
|
188
|
-
baseUrl: primaryEntry.baseUrl,
|
|
189
|
-
authToken,
|
|
190
|
-
agentKey: privateKey,
|
|
191
|
-
prompt: verifyPrompt,
|
|
192
|
-
expected: expectedResponse,
|
|
193
|
-
maxRounds: verifyRounds,
|
|
194
|
-
});
|
|
195
|
-
|
|
196
|
-
return {
|
|
197
|
-
userId,
|
|
198
|
-
authToken,
|
|
199
|
-
agentId,
|
|
200
|
-
privateKey,
|
|
201
|
-
agentUrl: `${primaryEntry.baseUrl}/${privateKey}`,
|
|
202
|
-
spaceId: attachSpaceId,
|
|
203
|
-
verify,
|
|
204
|
-
replicatedBases: allEntries.map((entry) => entry.baseUrl),
|
|
205
|
-
verifiedBase: primaryEntry.baseUrl,
|
|
206
|
-
agentRecord,
|
|
207
|
-
};
|
|
208
|
-
}
|
|
@@ -1,179 +0,0 @@
|
|
|
1
|
-
export const DEFAULT_CODING_AGENT_PROMPT = [
|
|
2
|
-
"你是空间里的私有代码助理。",
|
|
3
|
-
"底层模型来自 OpenAI 兼容接口。",
|
|
4
|
-
"默认输出中文,代码、路径和命令保持英文。",
|
|
5
|
-
"执行命令前先判断当前环境;环境不明确时先调用 checkEnv({check:'context'})。",
|
|
6
|
-
"Windows 默认使用 PowerShell 语法,Linux/macOS 默认使用 bash 语法。",
|
|
7
|
-
"开始动手前先理解需求和上下文,避免无关改动。",
|
|
8
|
-
"优先做可验证、可落地的修改,必要时先读取文件和环境。",
|
|
9
|
-
"涉及代码改动时,尽量给出最小但完整的实现,并说明验证方式。",
|
|
10
|
-
].join("\n");
|
|
11
|
-
|
|
12
|
-
export type BuildCodingAgentRecordOptions = {
|
|
13
|
-
userId: string;
|
|
14
|
-
now: number;
|
|
15
|
-
agentId: string;
|
|
16
|
-
name: string;
|
|
17
|
-
provider: string;
|
|
18
|
-
model: string;
|
|
19
|
-
apiSource: "custom" | "platform";
|
|
20
|
-
tools: string[];
|
|
21
|
-
tags: string[];
|
|
22
|
-
introduction?: string;
|
|
23
|
-
greeting?: string;
|
|
24
|
-
prompt?: string;
|
|
25
|
-
providerUrl?: string;
|
|
26
|
-
apiKey?: string;
|
|
27
|
-
apiKeyHeader?: string;
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
export type CustomCodingAgentRecordPlanOptions = {
|
|
31
|
-
agentId?: string;
|
|
32
|
-
apiKey: string;
|
|
33
|
-
apiKeyHeader?: string;
|
|
34
|
-
providerUrl: string;
|
|
35
|
-
model: string;
|
|
36
|
-
name: string;
|
|
37
|
-
providerTag?: string;
|
|
38
|
-
introduction?: string;
|
|
39
|
-
greeting?: string;
|
|
40
|
-
prompt?: string;
|
|
41
|
-
tags?: string[];
|
|
42
|
-
tools: string[];
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
export type CustomCodingAgentRecordPlan = {
|
|
46
|
-
agentId: string;
|
|
47
|
-
normalizedProviderUrl: string;
|
|
48
|
-
normalizedApiKey: string;
|
|
49
|
-
buildRecord: (args: { userId: string; now: number }) => Record<string, any>;
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
export function deterministicId(prefix: string, seed: string): string {
|
|
53
|
-
let hash = 0x811c9dc5;
|
|
54
|
-
for (let index = 0; index < seed.length; index++) {
|
|
55
|
-
hash ^= seed.charCodeAt(index);
|
|
56
|
-
hash = (hash * 0x01000193) >>> 0;
|
|
57
|
-
}
|
|
58
|
-
const suffix = hash.toString(36).toUpperCase().padStart(14, "0");
|
|
59
|
-
return (prefix + suffix).slice(0, 26);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export function inferHostTag(providerUrl: string): string {
|
|
63
|
-
try {
|
|
64
|
-
return new URL(providerUrl).hostname.replace(/^www\./, "").replace(/\./g, "-");
|
|
65
|
-
} catch {
|
|
66
|
-
return "custom";
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
function isLocalProviderUrl(providerUrl: string | undefined): boolean {
|
|
71
|
-
if (!providerUrl) return false;
|
|
72
|
-
try {
|
|
73
|
-
const hostname = new URL(providerUrl).hostname.toLowerCase();
|
|
74
|
-
return hostname === "127.0.0.1" || hostname === "localhost" || hostname === "::1";
|
|
75
|
-
} catch {
|
|
76
|
-
return false;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
export function buildCodingAgentRecord(options: BuildCodingAgentRecordOptions) {
|
|
81
|
-
const normalizedProviderUrl = options.providerUrl?.trim().replace(/\/+$/, "");
|
|
82
|
-
return {
|
|
83
|
-
type: "agent",
|
|
84
|
-
id: options.agentId,
|
|
85
|
-
userId: options.userId,
|
|
86
|
-
name: options.name.trim(),
|
|
87
|
-
introduction: options.introduction ?? `使用 ${options.provider} 的私有代码助理。`,
|
|
88
|
-
greeting:
|
|
89
|
-
options.greeting ??
|
|
90
|
-
`你好,我是 ${options.name}。你可以直接让我读项目、改代码、查环境、写脚本。`,
|
|
91
|
-
prompt: options.prompt ?? DEFAULT_CODING_AGENT_PROMPT,
|
|
92
|
-
apiSource: options.apiSource,
|
|
93
|
-
provider: options.provider,
|
|
94
|
-
model: options.model.trim(),
|
|
95
|
-
...(normalizedProviderUrl ? { customProviderUrl: normalizedProviderUrl } : {}),
|
|
96
|
-
...(options.apiKey?.trim() ? { apiKey: options.apiKey.trim() } : {}),
|
|
97
|
-
...(options.apiKeyHeader?.trim() ? { apiKeyHeader: options.apiKeyHeader.trim() } : {}),
|
|
98
|
-
useServerProxy: true,
|
|
99
|
-
hasVision: false,
|
|
100
|
-
inputPrice: 0,
|
|
101
|
-
outputPrice: 0,
|
|
102
|
-
isPublic: false,
|
|
103
|
-
tools: [...options.tools],
|
|
104
|
-
tags: [...new Set(options.tags.filter(Boolean))],
|
|
105
|
-
...(isLocalProviderUrl(normalizedProviderUrl)
|
|
106
|
-
? {
|
|
107
|
-
runtimeBinding: {
|
|
108
|
-
kind: "desktop-local-provider",
|
|
109
|
-
providerUrl: normalizedProviderUrl,
|
|
110
|
-
},
|
|
111
|
-
}
|
|
112
|
-
: {}),
|
|
113
|
-
whitelist: [],
|
|
114
|
-
createdAt: options.now,
|
|
115
|
-
updatedAt: options.now,
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
export function resolveCustomCodingAgentRecordPlan(
|
|
120
|
-
options: CustomCodingAgentRecordPlanOptions
|
|
121
|
-
): CustomCodingAgentRecordPlan {
|
|
122
|
-
const providerTag = options.providerTag ?? "custom";
|
|
123
|
-
const normalizedProviderUrl = options.providerUrl.trim().replace(/\/+$/, "");
|
|
124
|
-
const normalizedApiKey = options.apiKey.trim();
|
|
125
|
-
const model = options.model.trim();
|
|
126
|
-
const name = options.name.trim();
|
|
127
|
-
|
|
128
|
-
if (!normalizedApiKey) {
|
|
129
|
-
throw new Error("缺少 API key。");
|
|
130
|
-
}
|
|
131
|
-
if (!normalizedProviderUrl) {
|
|
132
|
-
throw new Error("缺少 provider url。");
|
|
133
|
-
}
|
|
134
|
-
if (!model) {
|
|
135
|
-
throw new Error("缺少 model。");
|
|
136
|
-
}
|
|
137
|
-
if (!name) {
|
|
138
|
-
throw new Error("缺少 agent 名称。");
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
const agentId =
|
|
142
|
-
options.agentId ??
|
|
143
|
-
deterministicId(
|
|
144
|
-
"01CUSTOMCODEA",
|
|
145
|
-
`custom-coding-agent:${normalizedProviderUrl}:${model}:${name}`
|
|
146
|
-
);
|
|
147
|
-
const introduction =
|
|
148
|
-
options.introduction ??
|
|
149
|
-
`使用 ${providerTag} 提供的 OpenAI 兼容接口的私有代码助理,适合代码阅读、修改、命令执行与开发协作。`;
|
|
150
|
-
const greeting =
|
|
151
|
-
options.greeting ??
|
|
152
|
-
`你好,我是 ${name}。你可以直接让我读项目、改代码、查环境、写脚本。`;
|
|
153
|
-
const prompt = options.prompt ?? DEFAULT_CODING_AGENT_PROMPT;
|
|
154
|
-
const tags = options.tags ?? [providerTag, inferHostTag(normalizedProviderUrl), "coding"];
|
|
155
|
-
|
|
156
|
-
return {
|
|
157
|
-
agentId,
|
|
158
|
-
normalizedProviderUrl,
|
|
159
|
-
normalizedApiKey,
|
|
160
|
-
buildRecord: ({ userId, now }) =>
|
|
161
|
-
buildCodingAgentRecord({
|
|
162
|
-
userId,
|
|
163
|
-
now,
|
|
164
|
-
agentId,
|
|
165
|
-
name,
|
|
166
|
-
introduction,
|
|
167
|
-
greeting,
|
|
168
|
-
prompt,
|
|
169
|
-
apiSource: "custom",
|
|
170
|
-
provider: "custom",
|
|
171
|
-
model,
|
|
172
|
-
providerUrl: normalizedProviderUrl,
|
|
173
|
-
apiKey: normalizedApiKey,
|
|
174
|
-
apiKeyHeader: options.apiKeyHeader,
|
|
175
|
-
tools: options.tools,
|
|
176
|
-
tags,
|
|
177
|
-
}),
|
|
178
|
-
};
|
|
179
|
-
}
|
package/cli/dialogDataAccess.ts
DELETED
|
@@ -1,186 +0,0 @@
|
|
|
1
|
-
import { fetchMessages } from "../chat/messages/fetchMessages";
|
|
2
|
-
import { getReadableCliDb } from "./agentCommandSupport";
|
|
3
|
-
import type { DialogHttpAttempt, DialogReadSource } from "./dialogReadHelpers";
|
|
4
|
-
|
|
5
|
-
export function isLocalBaseUrl(baseUrl: string) {
|
|
6
|
-
try {
|
|
7
|
-
const hostname = new URL(baseUrl).hostname;
|
|
8
|
-
return hostname === "localhost" || hostname === "127.0.0.1";
|
|
9
|
-
} catch {
|
|
10
|
-
return false;
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
async function fetchJsonWithFallback(
|
|
15
|
-
url: string,
|
|
16
|
-
init: RequestInit,
|
|
17
|
-
fetchImpl: typeof fetch,
|
|
18
|
-
fallbackFetchImpl?: typeof fetch
|
|
19
|
-
) {
|
|
20
|
-
try {
|
|
21
|
-
return await fetchImpl(url, init);
|
|
22
|
-
} catch (error) {
|
|
23
|
-
if (!fallbackFetchImpl) throw error;
|
|
24
|
-
return fallbackFetchImpl(url, init);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
async function readDialogOverHttp(args: {
|
|
29
|
-
authToken: string;
|
|
30
|
-
base: string;
|
|
31
|
-
dialogId: string;
|
|
32
|
-
dialogKey: string;
|
|
33
|
-
fetchImpl: typeof fetch;
|
|
34
|
-
fallbackFetchImpl?: typeof fetch;
|
|
35
|
-
limit: number;
|
|
36
|
-
}) {
|
|
37
|
-
const authHeaders = {
|
|
38
|
-
...(args.authToken ? { Authorization: `Bearer ${args.authToken}` } : {}),
|
|
39
|
-
"Content-Type": "application/json",
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
const readViaBridge = async () => {
|
|
43
|
-
const bridgeRes = await fetchJsonWithFallback(
|
|
44
|
-
`${args.base}/api/dialog-read`,
|
|
45
|
-
{
|
|
46
|
-
method: "POST",
|
|
47
|
-
headers: authHeaders,
|
|
48
|
-
body: JSON.stringify({
|
|
49
|
-
dialogKey: args.dialogKey,
|
|
50
|
-
dialogId: args.dialogId,
|
|
51
|
-
limit: args.limit,
|
|
52
|
-
}),
|
|
53
|
-
},
|
|
54
|
-
args.fetchImpl,
|
|
55
|
-
args.fallbackFetchImpl
|
|
56
|
-
);
|
|
57
|
-
if (!bridgeRes.ok) {
|
|
58
|
-
throw Object.assign(new Error(`dialog read bridge failed: HTTP ${bridgeRes.status}`), {
|
|
59
|
-
status: bridgeRes.status,
|
|
60
|
-
base: args.base,
|
|
61
|
-
stage: "bridge",
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
const payload = await bridgeRes.json();
|
|
65
|
-
if (!payload?.ok) {
|
|
66
|
-
throw Object.assign(
|
|
67
|
-
new Error(`dialog read bridge failed: ${payload?.error ?? "unknown error"}`),
|
|
68
|
-
{
|
|
69
|
-
status: 500,
|
|
70
|
-
base: args.base,
|
|
71
|
-
stage: "bridge",
|
|
72
|
-
}
|
|
73
|
-
);
|
|
74
|
-
}
|
|
75
|
-
return {
|
|
76
|
-
meta: payload.meta,
|
|
77
|
-
msgs: payload.msgs,
|
|
78
|
-
source: "http" as DialogReadSource,
|
|
79
|
-
};
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
const metaRes = await fetchJsonWithFallback(
|
|
83
|
-
`${args.base}/api/v1/db/read/${encodeURIComponent(args.dialogKey)}`,
|
|
84
|
-
{
|
|
85
|
-
headers: args.authToken ? { Authorization: `Bearer ${args.authToken}` } : {},
|
|
86
|
-
},
|
|
87
|
-
args.fetchImpl,
|
|
88
|
-
args.fallbackFetchImpl
|
|
89
|
-
);
|
|
90
|
-
|
|
91
|
-
if (!metaRes.ok) {
|
|
92
|
-
if (metaRes.status === 401 || metaRes.status === 403) {
|
|
93
|
-
return readViaBridge();
|
|
94
|
-
}
|
|
95
|
-
throw Object.assign(new Error(`read dialog meta failed: HTTP ${metaRes.status}`), {
|
|
96
|
-
status: metaRes.status,
|
|
97
|
-
base: args.base,
|
|
98
|
-
stage: "meta",
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
const metaPayload = await metaRes.json().catch(() => ({}));
|
|
103
|
-
const meta = metaPayload?.data ?? metaPayload;
|
|
104
|
-
|
|
105
|
-
const msgsRes = await fetchJsonWithFallback(
|
|
106
|
-
`${args.base}/rpc/getConvMsgs`,
|
|
107
|
-
{
|
|
108
|
-
method: "POST",
|
|
109
|
-
headers: authHeaders,
|
|
110
|
-
body: JSON.stringify({ dialogId: args.dialogId, limit: args.limit }),
|
|
111
|
-
},
|
|
112
|
-
args.fetchImpl,
|
|
113
|
-
args.fallbackFetchImpl
|
|
114
|
-
);
|
|
115
|
-
|
|
116
|
-
if (!msgsRes.ok) {
|
|
117
|
-
if (msgsRes.status === 401 || msgsRes.status === 403) {
|
|
118
|
-
return readViaBridge();
|
|
119
|
-
}
|
|
120
|
-
throw Object.assign(new Error(`read dialog messages failed: HTTP ${msgsRes.status}`), {
|
|
121
|
-
status: msgsRes.status,
|
|
122
|
-
base: args.base,
|
|
123
|
-
stage: "messages",
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
const msgs = await msgsRes.json();
|
|
128
|
-
return {
|
|
129
|
-
meta,
|
|
130
|
-
msgs,
|
|
131
|
-
source: "http" as DialogReadSource,
|
|
132
|
-
};
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
export async function tryHttpDialogCandidates(args: {
|
|
136
|
-
authToken: string;
|
|
137
|
-
bases: string[];
|
|
138
|
-
dialogId: string;
|
|
139
|
-
dialogKey: string;
|
|
140
|
-
fetchImpl: typeof fetch;
|
|
141
|
-
fallbackFetchImpl?: typeof fetch;
|
|
142
|
-
limit: number;
|
|
143
|
-
}) {
|
|
144
|
-
const attempts: DialogHttpAttempt[] = [];
|
|
145
|
-
for (const base of args.bases) {
|
|
146
|
-
try {
|
|
147
|
-
const result = await readDialogOverHttp({
|
|
148
|
-
authToken: args.authToken,
|
|
149
|
-
base,
|
|
150
|
-
dialogId: args.dialogId,
|
|
151
|
-
dialogKey: args.dialogKey,
|
|
152
|
-
fetchImpl: args.fetchImpl,
|
|
153
|
-
fallbackFetchImpl: args.fallbackFetchImpl,
|
|
154
|
-
limit: args.limit,
|
|
155
|
-
});
|
|
156
|
-
attempts.push({ base, ok: true });
|
|
157
|
-
return { ...result, resolvedBase: base, attempts };
|
|
158
|
-
} catch (error) {
|
|
159
|
-
const status =
|
|
160
|
-
typeof error === "object" && error !== null && "status" in error
|
|
161
|
-
? Number((error as any).status)
|
|
162
|
-
: undefined;
|
|
163
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
164
|
-
attempts.push({ base, ok: false, status, message });
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
throw Object.assign(new Error("All HTTP dialog reads failed"), { attempts });
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
export async function readDialogFromLocalDb(args: {
|
|
171
|
-
db: Awaited<ReturnType<typeof getReadableCliDb>>;
|
|
172
|
-
dialogId: string;
|
|
173
|
-
dialogKey: string;
|
|
174
|
-
limit: number;
|
|
175
|
-
}) {
|
|
176
|
-
const meta = await args.db.get(args.dialogKey);
|
|
177
|
-
const msgs = await fetchMessages(args.db, args.dialogId, {
|
|
178
|
-
limit: args.limit,
|
|
179
|
-
throwOnError: true,
|
|
180
|
-
});
|
|
181
|
-
return {
|
|
182
|
-
meta,
|
|
183
|
-
msgs,
|
|
184
|
-
source: "local-db-fallback" as DialogReadSource,
|
|
185
|
-
};
|
|
186
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { createEnvCommand } from "./cliCommandFactories";
|
|
2
|
-
import type { CommandEntry } from "./cliCommandTypes";
|
|
3
|
-
import { runDialogReadCommand } from "./dialogReadCommands";
|
|
4
|
-
import { runDialogStatusCommand } from "./dialogStatusCommands";
|
|
5
|
-
|
|
6
|
-
export function getDialogInternalCommandEntries(): CommandEntry[] {
|
|
7
|
-
return [
|
|
8
|
-
createEnvCommand(["dialog", "read"], "Read a dialog", runDialogReadCommand),
|
|
9
|
-
createEnvCommand(["dialog", "status"], "Read compact dialog status", runDialogStatusCommand),
|
|
10
|
-
];
|
|
11
|
-
}
|