Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/large-eyes-hide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@plotday/sdk": patch
---

Changed: plot agent logs takes id from package.json
37 changes: 35 additions & 2 deletions sdk/cli/commands/agent-logs.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
import * as fs from "fs";
import * as path from "path";

import * as out from "../utils/output";
import { getGlobalTokenPath } from "../utils/token";
import { handleSSEStream } from "../utils/sse";

interface PackageJson {
plotAgentId?: string;
}

interface AgentLogsOptions {
agentId: string;
agentId?: string;
id?: string;
dir?: string;
environment?: string;
deployToken?: string;
apiUrl: string;
Expand All @@ -15,7 +22,33 @@ interface AgentLogsOptions {
* Stream agent logs in real-time
*/
export async function agentLogsCommand(options: AgentLogsOptions) {
const { agentId, environment = "personal", apiUrl } = options;
const { environment = "personal", apiUrl, dir = process.cwd() } = options;

// Determine agent ID from options, positional arg, or package.json
let agentId = options.id || options.agentId;

if (!agentId) {
// Try to read from package.json
const packageJsonPath = path.join(dir, "package.json");
if (fs.existsSync(packageJsonPath)) {
try {
const packageJsonContent = fs.readFileSync(packageJsonPath, "utf-8");
const packageJson: PackageJson = JSON.parse(packageJsonContent);
agentId = packageJson.plotAgentId;
} catch (error) {
out.error("Failed to parse package.json", String(error));
process.exit(1);
}
}
}

if (!agentId) {
out.error(
"Agent ID required",
"Provide agent ID as argument, via --id flag, or add 'plotAgentId' to package.json"
);
process.exit(1);
}

// Load deploy token
let deployToken = options.deployToken;
Expand Down
10 changes: 8 additions & 2 deletions sdk/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,22 +118,28 @@ agent
});

agent
.command("logs <agent-id>")
.command("logs [agent-id]")
.description("Stream real-time logs from an agent")
.option("-d, --dir <directory>", "Agent directory", process.cwd())
.option("--id <agentId>", "Agent ID")
.option(
"-e, --environment <env>",
"Agent environment (personal, private, review)",
"personal"
)
.option("--deploy-token <token>", "Authentication token")
.action(function (this: Command, agentId: string) {
.action(function (this: Command, agentId?: string) {
const opts = this.optsWithGlobals() as {
dir?: string;
id?: string;
environment?: string;
deployToken?: string;
apiUrl: string;
};
return agentLogsCommand({
agentId,
id: opts.id,
dir: opts.dir,
environment: opts.environment,
deployToken: opts.deployToken,
apiUrl: opts.apiUrl,
Expand Down