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
package/cli/agentPullCommand.ts
CHANGED
|
@@ -1,20 +1,14 @@
|
|
|
1
|
+
import { DEFAULT_NOLO_SERVER_URL } from "./defaultServer";
|
|
1
2
|
import { getDefaultCliLocalRuntimeDb } from "./localRuntimeDb";
|
|
2
3
|
import type { CliLocalRuntimeDb } from "./client/localRuntimeAdapter";
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
buildCurrentUserPlatformAgentCandidateKeys,
|
|
6
|
-
resolveCliAgentKeyInput,
|
|
7
|
-
} from "./agentAliases";
|
|
8
|
-
import { resolveAgentRecordFromHybridStore } from "./agentRecordHelpers";
|
|
9
|
-
import {
|
|
10
|
-
parseUserIdFromAuthToken,
|
|
11
|
-
readCliOptionValue,
|
|
12
|
-
resolveAuthToken,
|
|
13
|
-
resolveServerUrl,
|
|
14
|
-
} from "./cliEnvHelpers";
|
|
4
|
+
import { resolveCliAgentKeyInput } from "./agentAliases";
|
|
15
5
|
|
|
16
6
|
type EnvLike = Record<string, string | undefined>;
|
|
17
7
|
|
|
8
|
+
type OutputLike = {
|
|
9
|
+
write(chunk: string): unknown;
|
|
10
|
+
};
|
|
11
|
+
|
|
18
12
|
type AgentPullCommandDeps = {
|
|
19
13
|
env?: EnvLike;
|
|
20
14
|
output?: OutputLike;
|
|
@@ -27,7 +21,8 @@ export type ParsedAgentPullArgs = {
|
|
|
27
21
|
};
|
|
28
22
|
|
|
29
23
|
function readFlagValue(args: string[], flag: string) {
|
|
30
|
-
|
|
24
|
+
const index = args.indexOf(flag);
|
|
25
|
+
return index >= 0 ? args[index + 1] : undefined;
|
|
31
26
|
}
|
|
32
27
|
|
|
33
28
|
function positionalArgs(args: string[]) {
|
|
@@ -49,6 +44,14 @@ export function parseAgentPullArgs(args: string[]): ParsedAgentPullArgs | null {
|
|
|
49
44
|
return { agentKey: resolveCliAgentKeyInput(agentKey) };
|
|
50
45
|
}
|
|
51
46
|
|
|
47
|
+
function resolveServerUrl(env: EnvLike) {
|
|
48
|
+
return (env.NOLO_SERVER || env.BASE_URL || DEFAULT_NOLO_SERVER_URL).replace(/\/+$/, "");
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function resolveAuthToken(env: EnvLike) {
|
|
52
|
+
return env.AUTH_TOKEN || env.AUTH || env.BENCHMARK_AUTH_TOKEN || "";
|
|
53
|
+
}
|
|
54
|
+
|
|
52
55
|
function extractToolNames(record: any) {
|
|
53
56
|
if (Array.isArray(record?.toolNames)) return record.toolNames.filter((tool: unknown) => typeof tool === "string");
|
|
54
57
|
if (!Array.isArray(record?.tools)) return [];
|
|
@@ -110,58 +113,35 @@ export async function runAgentPullCommand(args: string[], deps: AgentPullCommand
|
|
|
110
113
|
return 1;
|
|
111
114
|
}
|
|
112
115
|
|
|
113
|
-
const serverUrl = resolveServerUrl(
|
|
114
|
-
const authToken = resolveAuthToken(
|
|
115
|
-
const currentUserId = parseUserIdFromAuthToken(authToken);
|
|
116
|
+
const serverUrl = resolveServerUrl(env);
|
|
117
|
+
const authToken = resolveAuthToken(env);
|
|
116
118
|
const fetchImpl = deps.fetchImpl ?? fetch;
|
|
117
119
|
const db = deps.db ?? await getDefaultCliLocalRuntimeDb();
|
|
118
|
-
|
|
119
|
-
let
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
agentInput,
|
|
126
|
-
cliArgs: args,
|
|
127
|
-
env,
|
|
128
|
-
db,
|
|
120
|
+
|
|
121
|
+
let record: any;
|
|
122
|
+
try {
|
|
123
|
+
record = await readRemoteAgent({
|
|
124
|
+
agentKey: parsed.agentKey,
|
|
125
|
+
serverUrl,
|
|
126
|
+
authToken,
|
|
129
127
|
fetchImpl,
|
|
130
128
|
});
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
let record: any = resolvedRecord;
|
|
140
|
-
if (!record) {
|
|
141
|
-
try {
|
|
142
|
-
record = await readRemoteAgent({
|
|
143
|
-
agentKey,
|
|
144
|
-
serverUrl,
|
|
145
|
-
authToken,
|
|
146
|
-
fetchImpl,
|
|
147
|
-
});
|
|
148
|
-
} catch (error) {
|
|
149
|
-
output.write(
|
|
150
|
-
`[nolo] Failed to pull ${agentKey} from ${serverUrl}: ${
|
|
151
|
-
error instanceof Error ? error.message : String(error)
|
|
152
|
-
}\n`
|
|
153
|
-
);
|
|
154
|
-
return 1;
|
|
155
|
-
}
|
|
129
|
+
} catch (error) {
|
|
130
|
+
output.write(
|
|
131
|
+
`[nolo] Failed to pull ${parsed.agentKey} from ${serverUrl}: ${
|
|
132
|
+
error instanceof Error ? error.message : String(error)
|
|
133
|
+
}\n`
|
|
134
|
+
);
|
|
135
|
+
return 1;
|
|
156
136
|
}
|
|
157
137
|
|
|
158
138
|
if (!record || typeof record !== "object") {
|
|
159
|
-
output.write(`[nolo] Server returned an empty agent record for ${agentKey}.\n`);
|
|
139
|
+
output.write(`[nolo] Server returned an empty agent record for ${parsed.agentKey}.\n`);
|
|
160
140
|
return 1;
|
|
161
141
|
}
|
|
162
142
|
|
|
163
|
-
const localRecord = normalizeAgentRecord(agentKey, record);
|
|
164
|
-
await db.put(agentKey, localRecord);
|
|
165
|
-
output.write(`[nolo] cached ${agentKey} in local LevelDB\n`);
|
|
143
|
+
const localRecord = normalizeAgentRecord(parsed.agentKey, record);
|
|
144
|
+
await db.put(parsed.agentKey, localRecord);
|
|
145
|
+
output.write(`[nolo] cached ${parsed.agentKey} in local LevelDB\n`);
|
|
166
146
|
return 0;
|
|
167
147
|
}
|
|
@@ -17,11 +17,11 @@ export async function runAgentReadCommand(
|
|
|
17
17
|
const output = deps.output ?? process.stdout;
|
|
18
18
|
const agentInput = args[0]?.trim();
|
|
19
19
|
if (!agentInput || agentInput === "--help" || agentInput === "-h") {
|
|
20
|
-
output.write("Usage: nolo agent read <agent
|
|
20
|
+
output.write("Usage: nolo agent read <agent>\n");
|
|
21
21
|
return agentInput ? 0 : 1;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
const authToken = resolveAuthToken(
|
|
24
|
+
const authToken = resolveAuthToken(env);
|
|
25
25
|
if (!authToken) {
|
|
26
26
|
output.write("[nolo] agent read requires an auth token. Run `nolo login` or set AUTH_TOKEN.\n");
|
|
27
27
|
return 1;
|
|
@@ -35,7 +35,6 @@ export async function runAgentReadCommand(
|
|
|
35
35
|
try {
|
|
36
36
|
const result = await resolveAgentRecordFromHybridStore({
|
|
37
37
|
agentInput,
|
|
38
|
-
cliArgs: args,
|
|
39
38
|
env,
|
|
40
39
|
db,
|
|
41
40
|
fetchImpl,
|
|
@@ -80,7 +79,7 @@ export async function runAgentUpdateCommand(
|
|
|
80
79
|
return args[0] ? 0 : 1;
|
|
81
80
|
}
|
|
82
81
|
|
|
83
|
-
const authToken = resolveAuthToken(
|
|
82
|
+
const authToken = resolveAuthToken(env);
|
|
84
83
|
if (!authToken) {
|
|
85
84
|
output.write("[nolo] agent update requires an auth token. Run `nolo login` or set AUTH_TOKEN.\n");
|
|
86
85
|
return 1;
|
|
@@ -98,7 +97,6 @@ export async function runAgentUpdateCommand(
|
|
|
98
97
|
|
|
99
98
|
try {
|
|
100
99
|
const built = await buildUpdatedAgentRecord({
|
|
101
|
-
cliArgs: args,
|
|
102
100
|
parsed,
|
|
103
101
|
env,
|
|
104
102
|
db,
|
|
@@ -1,14 +1,8 @@
|
|
|
1
1
|
import { readFileSync } from "node:fs";
|
|
2
|
-
import {
|
|
3
|
-
buildPrivateAgentKey,
|
|
4
|
-
buildCurrentUserPlatformAgentCandidateKeys,
|
|
5
|
-
resolveCliAgentKeyInput,
|
|
6
|
-
resolvePlatformAgentAliasSpec,
|
|
7
|
-
} from "./agentAliases";
|
|
2
|
+
import { resolveCliAgentKeyInput } from "./agentAliases";
|
|
8
3
|
import type { CliKvDb } from "./client/hybridRecordStore";
|
|
9
4
|
import { buildLocalAgentLookupKeys, shouldReadAgentKeyRemotely } from "./client/localAgentRecords";
|
|
10
5
|
import {
|
|
11
|
-
hasExplicitServerOverride,
|
|
12
6
|
parseUserIdFromAuthToken,
|
|
13
7
|
readOption,
|
|
14
8
|
resolveAuthToken,
|
|
@@ -16,7 +10,6 @@ import {
|
|
|
16
10
|
resolveServerUrl,
|
|
17
11
|
type EnvLike,
|
|
18
12
|
} from "./cliEnvHelpers";
|
|
19
|
-
import { parseSpaceIdFromInput, readSpaceRecordWithFallback } from "./spaceMutationHelpers";
|
|
20
13
|
|
|
21
14
|
const PROVIDER_COPY_FIELDS = [
|
|
22
15
|
"apiSource",
|
|
@@ -155,13 +148,10 @@ export async function queryUserRecords(args: {
|
|
|
155
148
|
fetchImpl: typeof fetch;
|
|
156
149
|
serverUrl: string;
|
|
157
150
|
userId: string;
|
|
158
|
-
type: "agent" | "cybot"
|
|
159
|
-
limit?: number;
|
|
151
|
+
type: "agent" | "cybot";
|
|
160
152
|
}) {
|
|
161
153
|
const res = await fetchWithTransportFallback(
|
|
162
|
-
`${args.serverUrl}/api/v1/db/query/${encodeURIComponent(args.userId)}
|
|
163
|
-
typeof args.limit === "number" && Number.isFinite(args.limit) ? `?limit=${args.limit}` : ""
|
|
164
|
-
}`,
|
|
154
|
+
`${args.serverUrl}/api/v1/db/query/${encodeURIComponent(args.userId)}`,
|
|
165
155
|
{
|
|
166
156
|
method: "POST",
|
|
167
157
|
headers: {
|
|
@@ -191,26 +181,6 @@ export async function writeAgentRecord(args: {
|
|
|
191
181
|
serverUrl: string;
|
|
192
182
|
userId: string;
|
|
193
183
|
record: Record<string, any>;
|
|
194
|
-
}) {
|
|
195
|
-
return writeDbRecord({
|
|
196
|
-
authToken: args.authToken,
|
|
197
|
-
dbKey: args.agentKey,
|
|
198
|
-
fallbackFetchImpl: args.fallbackFetchImpl,
|
|
199
|
-
fetchImpl: args.fetchImpl,
|
|
200
|
-
record: args.record,
|
|
201
|
-
serverUrl: args.serverUrl,
|
|
202
|
-
userId: args.userId,
|
|
203
|
-
});
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
export async function writeDbRecord(args: {
|
|
207
|
-
authToken: string;
|
|
208
|
-
dbKey: string;
|
|
209
|
-
fallbackFetchImpl?: typeof fetch;
|
|
210
|
-
fetchImpl: typeof fetch;
|
|
211
|
-
serverUrl: string;
|
|
212
|
-
userId: string;
|
|
213
|
-
record: Record<string, any>;
|
|
214
184
|
}) {
|
|
215
185
|
const res = await fetchWithTransportFallback(`${args.serverUrl}/api/v1/db/write/`, {
|
|
216
186
|
method: "POST",
|
|
@@ -219,11 +189,11 @@ export async function writeDbRecord(args: {
|
|
|
219
189
|
"Content-Type": "application/json",
|
|
220
190
|
},
|
|
221
191
|
body: JSON.stringify({
|
|
222
|
-
customKey: args.
|
|
192
|
+
customKey: args.agentKey,
|
|
223
193
|
userId: args.userId,
|
|
224
194
|
data: {
|
|
225
195
|
...args.record,
|
|
226
|
-
dbKey: args.
|
|
196
|
+
dbKey: args.agentKey,
|
|
227
197
|
},
|
|
228
198
|
}),
|
|
229
199
|
}, args);
|
|
@@ -233,145 +203,36 @@ export async function writeDbRecord(args: {
|
|
|
233
203
|
}
|
|
234
204
|
}
|
|
235
205
|
|
|
236
|
-
export async function deleteDbRecord(args: {
|
|
237
|
-
authToken: string;
|
|
238
|
-
dbKey: string;
|
|
239
|
-
fallbackFetchImpl?: typeof fetch;
|
|
240
|
-
fetchImpl: typeof fetch;
|
|
241
|
-
serverUrl: string;
|
|
242
|
-
userId: string;
|
|
243
|
-
}) {
|
|
244
|
-
const res = await fetchWithTransportFallback(
|
|
245
|
-
`${args.serverUrl}/api/v1/db/delete/${encodeURIComponent(args.dbKey)}?userId=${encodeURIComponent(args.userId)}`,
|
|
246
|
-
{
|
|
247
|
-
method: "DELETE",
|
|
248
|
-
headers: {
|
|
249
|
-
Authorization: `Bearer ${args.authToken}`,
|
|
250
|
-
},
|
|
251
|
-
},
|
|
252
|
-
args
|
|
253
|
-
);
|
|
254
|
-
const text = await res.text();
|
|
255
|
-
let data: any = {};
|
|
256
|
-
if (text) {
|
|
257
|
-
try {
|
|
258
|
-
data = JSON.parse(text);
|
|
259
|
-
} catch {
|
|
260
|
-
data = {};
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
if (res.status === 404) return "missing" as const;
|
|
264
|
-
if (!res.ok && res.status !== 204) {
|
|
265
|
-
throw new Error(`delete failed: HTTP ${res.status} ${JSON.stringify(data)}`);
|
|
266
|
-
}
|
|
267
|
-
return "deleted" as const;
|
|
268
|
-
}
|
|
269
|
-
|
|
270
206
|
export async function resolveAgentRecordFromHybridStore(args: {
|
|
271
207
|
agentInput: string;
|
|
272
|
-
cliArgs?: string[];
|
|
273
208
|
env: EnvLike;
|
|
274
209
|
db: CliKvDb;
|
|
275
210
|
fetchImpl: typeof fetch;
|
|
276
211
|
fallbackFetchImpl?: typeof fetch;
|
|
277
212
|
}) {
|
|
278
213
|
const agentKey = resolveCliAgentKeyInput(args.agentInput);
|
|
279
|
-
const authToken = resolveAuthToken(args.
|
|
280
|
-
const
|
|
281
|
-
const cliArgs = args.cliArgs ?? [];
|
|
282
|
-
const defaultServerUrl = resolveServerUrl(cliArgs, args.env);
|
|
283
|
-
const serverCandidates = resolveServerCandidates(cliArgs, args.env, defaultServerUrl);
|
|
284
|
-
const preferRemote = hasExplicitServerOverride(cliArgs);
|
|
285
|
-
const aliasSpec = resolvePlatformAgentAliasSpec(args.agentInput);
|
|
286
|
-
const rawSpaceInput = readOption(cliArgs, "--space");
|
|
287
|
-
const preferredLookupKeys = buildCurrentUserPlatformAgentCandidateKeys(
|
|
288
|
-
args.agentInput,
|
|
289
|
-
currentUserId
|
|
290
|
-
);
|
|
291
|
-
const collectSpaceAttachedCandidateKeys = (spaceRecord: any) => {
|
|
292
|
-
const contents = spaceRecord?.contents;
|
|
293
|
-
if (!contents || typeof contents !== "object") return [];
|
|
294
|
-
|
|
295
|
-
const currentUserPrivateKey =
|
|
296
|
-
currentUserId ? buildPrivateAgentKey(currentUserId, aliasSpec!.agentId) : null;
|
|
297
|
-
const canonicalMatches: string[] = [];
|
|
298
|
-
const otherMatches: string[] = [];
|
|
299
|
-
const currentUserMatches: string[] = [];
|
|
214
|
+
const authToken = resolveAuthToken(args.env);
|
|
215
|
+
const defaultServerUrl = resolveServerUrl(args.env);
|
|
300
216
|
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
? (value as any).contentKey.trim()
|
|
306
|
-
: entryKey.trim();
|
|
307
|
-
if (!contentKey || !contentKey.endsWith(`-${aliasSpec!.agentId}`)) continue;
|
|
308
|
-
if (contentKey === aliasSpec!.canonicalKey) {
|
|
309
|
-
canonicalMatches.push(contentKey);
|
|
310
|
-
continue;
|
|
311
|
-
}
|
|
312
|
-
if (currentUserPrivateKey && contentKey === currentUserPrivateKey) {
|
|
313
|
-
currentUserMatches.push(contentKey);
|
|
314
|
-
continue;
|
|
315
|
-
}
|
|
316
|
-
otherMatches.push(contentKey);
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
return Array.from(
|
|
320
|
-
new Set([
|
|
321
|
-
...canonicalMatches.sort(),
|
|
322
|
-
...otherMatches.sort(),
|
|
323
|
-
...currentUserMatches.sort(),
|
|
324
|
-
])
|
|
325
|
-
);
|
|
326
|
-
};
|
|
327
|
-
const resolveSpaceAttachedCandidateKeys = async () => {
|
|
328
|
-
if (!aliasSpec || !rawSpaceInput || !authToken) return [];
|
|
217
|
+
for (const key of buildLocalAgentLookupKeys({
|
|
218
|
+
agentRef: agentKey,
|
|
219
|
+
userId: parseUserIdFromAuthToken(authToken) || "local",
|
|
220
|
+
})) {
|
|
329
221
|
try {
|
|
330
|
-
const
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
const localMatches = collectSpaceAttachedCandidateKeys(localSpaceRecord);
|
|
339
|
-
if (localMatches.length > 0) return localMatches;
|
|
340
|
-
|
|
341
|
-
const spaceRecord = await readSpaceRecordWithFallback({
|
|
342
|
-
authToken,
|
|
343
|
-
db: {
|
|
344
|
-
...args.db,
|
|
345
|
-
get: async () => {
|
|
346
|
-
throw new Error("force remote refresh for shared space alias resolution");
|
|
347
|
-
},
|
|
348
|
-
},
|
|
349
|
-
fallbackFetchImpl: args.fallbackFetchImpl,
|
|
350
|
-
fetchImpl: args.fetchImpl,
|
|
351
|
-
serverCandidates,
|
|
352
|
-
spaceId,
|
|
353
|
-
});
|
|
354
|
-
if (spaceRecord && typeof args.db.put === "function") {
|
|
355
|
-
await args.db.put(`space-${spaceId}`, spaceRecord);
|
|
222
|
+
const record = await args.db.get(key);
|
|
223
|
+
if (record && typeof record === "object") {
|
|
224
|
+
return {
|
|
225
|
+
agentKey: key,
|
|
226
|
+
record,
|
|
227
|
+
source: record?.serverOrigin ? "remote-cache" : "local-cache",
|
|
228
|
+
} as const;
|
|
356
229
|
}
|
|
357
|
-
return collectSpaceAttachedCandidateKeys(spaceRecord);
|
|
358
230
|
} catch {
|
|
359
|
-
|
|
231
|
+
// local miss
|
|
360
232
|
}
|
|
361
|
-
};
|
|
362
|
-
const spaceAttachedLookupKeys = await resolveSpaceAttachedCandidateKeys();
|
|
363
|
-
const lookupKeys =
|
|
364
|
-
spaceAttachedLookupKeys.length > 0
|
|
365
|
-
? Array.from(new Set([...spaceAttachedLookupKeys, ...preferredLookupKeys]))
|
|
366
|
-
: preferredLookupKeys.length > 0
|
|
367
|
-
? preferredLookupKeys
|
|
368
|
-
: buildLocalAgentLookupKeys({
|
|
369
|
-
agentRef: agentKey,
|
|
370
|
-
userId: currentUserId || "local",
|
|
371
|
-
});
|
|
372
233
|
|
|
373
|
-
|
|
374
|
-
for (const serverUrl of
|
|
234
|
+
if (!shouldReadAgentKeyRemotely(key)) continue;
|
|
235
|
+
for (const serverUrl of resolveServerCandidates(args.env, defaultServerUrl)) {
|
|
375
236
|
try {
|
|
376
237
|
const remoteRecord = await readAgentRecord({
|
|
377
238
|
agentKey: key,
|
|
@@ -391,31 +252,6 @@ export async function resolveAgentRecordFromHybridStore(args: {
|
|
|
391
252
|
// try next
|
|
392
253
|
}
|
|
393
254
|
}
|
|
394
|
-
return null;
|
|
395
|
-
};
|
|
396
|
-
|
|
397
|
-
for (const key of lookupKeys) {
|
|
398
|
-
if (preferRemote && shouldReadAgentKeyRemotely(key)) {
|
|
399
|
-
const remoteFirst = await readRemoteRecord(key);
|
|
400
|
-
if (remoteFirst) return remoteFirst;
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
try {
|
|
404
|
-
const record = await args.db.get(key);
|
|
405
|
-
if (record && typeof record === "object") {
|
|
406
|
-
return {
|
|
407
|
-
agentKey: key,
|
|
408
|
-
record,
|
|
409
|
-
source: record?.serverOrigin ? "remote-cache" : "local-cache",
|
|
410
|
-
} as const;
|
|
411
|
-
}
|
|
412
|
-
} catch {
|
|
413
|
-
// local miss
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
if (!shouldReadAgentKeyRemotely(key)) continue;
|
|
417
|
-
const remoteFallback = await readRemoteRecord(key);
|
|
418
|
-
if (remoteFallback) return remoteFallback;
|
|
419
255
|
}
|
|
420
256
|
|
|
421
257
|
return null;
|
|
@@ -487,7 +323,6 @@ export function parseAgentUpdateArgs(args: string[]) {
|
|
|
487
323
|
}
|
|
488
324
|
|
|
489
325
|
export async function buildUpdatedAgentRecord(args: {
|
|
490
|
-
cliArgs?: string[];
|
|
491
326
|
parsed: NonNullable<ReturnType<typeof parseAgentUpdateArgs>>;
|
|
492
327
|
env: EnvLike;
|
|
493
328
|
db: CliKvDb;
|
|
@@ -497,14 +332,13 @@ export async function buildUpdatedAgentRecord(args: {
|
|
|
497
332
|
}) {
|
|
498
333
|
const cached = await resolveAgentRecordFromHybridStore({
|
|
499
334
|
agentInput: args.parsed.agentInput,
|
|
500
|
-
cliArgs: args.cliArgs,
|
|
501
335
|
env: args.env,
|
|
502
336
|
db: args.db,
|
|
503
337
|
fetchImpl: args.fetchImpl,
|
|
504
338
|
fallbackFetchImpl: args.fallbackFetchImpl,
|
|
505
339
|
});
|
|
506
340
|
const agentKey = cached?.agentKey ?? resolveCliAgentKeyInput(args.parsed.agentInput);
|
|
507
|
-
const serverUrl = cached?.record?.serverOrigin ?? resolveServerUrl(args.
|
|
341
|
+
const serverUrl = cached?.record?.serverOrigin ?? resolveServerUrl(args.env);
|
|
508
342
|
const currentRecord = await readAgentRecord({
|
|
509
343
|
agentKey,
|
|
510
344
|
authToken: args.authToken,
|
|
@@ -516,7 +350,6 @@ export async function buildUpdatedAgentRecord(args: {
|
|
|
516
350
|
if (args.parsed.copyProviderFrom) {
|
|
517
351
|
const providerSource = await resolveAgentRecordFromHybridStore({
|
|
518
352
|
agentInput: args.parsed.copyProviderFrom,
|
|
519
|
-
cliArgs: args.cliArgs,
|
|
520
353
|
env: args.env,
|
|
521
354
|
db: args.db,
|
|
522
355
|
fetchImpl: args.fetchImpl,
|