@posthog/agent 2.3.709 → 2.3.727
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/dist/agent.js +1 -1
- package/dist/agent.js.map +1 -1
- package/dist/handoff-checkpoint.js.map +1 -1
- package/dist/posthog-api.d.ts +1 -1
- package/dist/posthog-api.js +1 -1
- package/dist/posthog-api.js.map +1 -1
- package/dist/resume.js.map +1 -1
- package/dist/server/agent-server.js +4 -1
- package/dist/server/agent-server.js.map +1 -1
- package/dist/server/bin.cjs +4 -1
- package/dist/server/bin.cjs.map +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +1 -1
- package/src/server/agent-server.configure-environment.test.ts +39 -1
- package/src/server/agent-server.ts +2 -1
- package/src/types.ts +2 -1
- package/src/utils/gateway.ts +8 -1
package/dist/types.d.ts
CHANGED
|
@@ -26,7 +26,7 @@ interface Task {
|
|
|
26
26
|
slug?: string;
|
|
27
27
|
title: string;
|
|
28
28
|
description: string;
|
|
29
|
-
origin_product: "error_tracking" | "eval_clusters" | "user_created" | "support_queue" | "session_summaries" | "signal_report";
|
|
29
|
+
origin_product: "error_tracking" | "eval_clusters" | "user_created" | "support_queue" | "session_summaries" | "signal_report" | "slack";
|
|
30
30
|
signal_report?: string | null;
|
|
31
31
|
github_integration?: number | null;
|
|
32
32
|
repository: string;
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type {\n GitHandoffCheckpoint,\n HandoffLocalGitState as GitHandoffLocalGitState,\n} from \"@posthog/git/handoff\";\n\n/**\n * Stored custom notification following ACP extensibility model.\n * Custom notifications use underscore-prefixed methods (e.g., `_posthog/phase_start`).\n * See: https://agentclientprotocol.com/docs/extensibility\n */\nexport interface StoredNotification {\n type: \"notification\";\n /** When this notification was stored */\n timestamp: string;\n /** JSON-RPC 2.0 notification (no id field = notification, not request) */\n notification: {\n jsonrpc: \"2.0\";\n method: string;\n params?: Record<string, unknown>;\n };\n}\n\n/**\n * Type alias for stored log entries.\n */\nexport type StoredEntry = StoredNotification;\n\n// PostHog Task model (matches PostHog Code's OpenAPI schema)\nexport interface Task {\n id: string;\n task_number?: number;\n slug?: string;\n title: string;\n description: string;\n origin_product:\n | \"error_tracking\"\n | \"eval_clusters\"\n | \"user_created\"\n | \"support_queue\"\n | \"session_summaries\"\n | \"signal_report\";\n signal_report?: string | null; // Inbox report UUID when origin_product is \"signal_report\"\n github_integration?: number | null;\n repository: string; // Format: \"organization/repository\" (e.g., \"posthog/posthog-js\")\n json_schema?: Record<string, unknown> | null; // JSON schema for task output validation\n internal?: boolean;\n created_at: string;\n updated_at: string;\n created_by?: {\n id: number;\n uuid: string;\n distinct_id: string;\n first_name: string;\n email: string;\n };\n latest_run?: TaskRun;\n}\n\n// Log entry structure for TaskRun.log\n\nexport type ArtifactType =\n | \"plan\"\n | \"context\"\n | \"reference\"\n | \"output\"\n | \"artifact\"\n | \"user_attachment\";\n\nexport interface TaskRunArtifact {\n id?: string;\n name: string;\n type: ArtifactType;\n source?: string;\n size?: number;\n content_type?: string;\n storage_path?: string;\n uploaded_at?: string;\n}\n\nexport type TaskRunStatus =\n | \"not_started\"\n | \"queued\"\n | \"in_progress\"\n | \"completed\"\n | \"failed\"\n | \"cancelled\";\n\nexport type TaskRunEnvironment = \"local\" | \"cloud\";\n\n// TaskRun model - represents individual execution runs of tasks\nexport interface TaskRun {\n id: string;\n task: string; // Task ID\n team: number;\n branch: string | null;\n stage: string | null; // Current stage (e.g., 'research', 'plan', 'build')\n environment: TaskRunEnvironment;\n status: TaskRunStatus;\n log_url: string;\n error_message: string | null;\n output: Record<string, unknown> | null; // Structured output (PR URL, commit SHA, etc.)\n state: Record<string, unknown>; // Intermediate run state (defaults to {}, never null)\n artifacts?: TaskRunArtifact[];\n created_at: string;\n updated_at: string;\n completed_at: string | null;\n}\n\nexport interface ProcessSpawnedCallback {\n onProcessSpawned?: (info: {\n pid: number;\n command: string;\n sessionId?: string;\n }) => void;\n onProcessExited?: (pid: number) => void;\n onMcpServersReady?: (serverNames: string[]) => void;\n}\n\nexport interface TaskExecutionOptions {\n repositoryPath?: string;\n adapter?: \"claude\" | \"codex\";\n model?: string;\n gatewayUrl?: string;\n codexBinaryPath?: string;\n instructions?: string;\n processCallbacks?: ProcessSpawnedCallback;\n /** Callback invoked when the agent calls the create_output tool for structured output */\n onStructuredOutput?: (output: Record<string, unknown>) => Promise<void>;\n /** Additional directories the agent process can access beyond cwd. */\n additionalDirectories?: string[];\n}\n\nexport type LogLevel = \"debug\" | \"info\" | \"warn\" | \"error\";\n\nexport type OnLogCallback = (\n level: LogLevel,\n scope: string,\n message: string,\n data?: unknown,\n) => void;\n\nexport interface PostHogAPIConfig {\n apiUrl: string;\n getApiKey: () => string | Promise<string>;\n refreshApiKey?: () => string | Promise<string>;\n projectId: number;\n userAgent?: string;\n}\n\nexport interface OtelTransportConfig {\n /** PostHog ingest host, e.g., \"https://us.i.posthog.com\" */\n host: string;\n /** Project API key */\n apiKey: string;\n /** Override the logs endpoint path (default: /i/v1/logs) */\n logsPath?: string;\n}\n\nexport interface AgentConfig {\n posthog?: PostHogAPIConfig;\n /** OTEL transport config for shipping logs to PostHog Logs */\n otelTransport?: OtelTransportConfig;\n /** Skip session log persistence (e.g. for preview sessions with no real task) */\n skipLogPersistence?: boolean;\n /** Local cache path for instant log loading (e.g., ~/.posthog-code) */\n localCachePath?: string;\n /**\n * Annotate files the agent reads with PostHog enrichment (event volume,\n * flag rollout/staleness, experiment links). Defaults to enabled when\n * `posthog` config is present; set `{ enabled: false }` to opt out.\n */\n enricher?: { enabled?: boolean };\n debug?: boolean;\n onLog?: OnLogCallback;\n}\n\n// Device info for tracking where work happens\nexport interface DeviceInfo {\n type: \"local\" | \"cloud\";\n name?: string;\n}\n\n// Agent execution mode - for tracking interactive vs background runs, when backgrounded an agent will continue working without asking questions\nexport type AgentMode = \"interactive\" | \"background\";\n\n// Git file status codes\nexport type FileStatus = \"A\" | \"M\" | \"D\";\n\nexport interface FileChange {\n path: string;\n status: FileStatus;\n}\n\nexport type HandoffLocalGitState = GitHandoffLocalGitState;\n\nexport interface GitCheckpoint extends GitHandoffCheckpoint {\n artifactPath?: string;\n indexArtifactPath?: string;\n}\n\nexport interface GitCheckpointEvent extends GitCheckpoint {\n device?: DeviceInfo;\n}\n\n/**\n * Keeps the emitted `@posthog/agent/types` entrypoint as a runtime ESM module.\n *\n * `export {}` is stripped by tsup in this package, which leaves `dist/types.js`\n * empty and breaks downstream type resolution for the exported subpath.\n */\nexport const AGENT_TYPES_MODULE = true;\n"],"mappings":";
|
|
1
|
+
{"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type {\n GitHandoffCheckpoint,\n HandoffLocalGitState as GitHandoffLocalGitState,\n} from \"@posthog/git/handoff\";\n\n/**\n * Stored custom notification following ACP extensibility model.\n * Custom notifications use underscore-prefixed methods (e.g., `_posthog/phase_start`).\n * See: https://agentclientprotocol.com/docs/extensibility\n */\nexport interface StoredNotification {\n type: \"notification\";\n /** When this notification was stored */\n timestamp: string;\n /** JSON-RPC 2.0 notification (no id field = notification, not request) */\n notification: {\n jsonrpc: \"2.0\";\n method: string;\n params?: Record<string, unknown>;\n };\n}\n\n/**\n * Type alias for stored log entries.\n */\nexport type StoredEntry = StoredNotification;\n\n// PostHog Task model (matches PostHog Code's OpenAPI schema)\nexport interface Task {\n id: string;\n task_number?: number;\n slug?: string;\n title: string;\n description: string;\n origin_product:\n | \"error_tracking\"\n | \"eval_clusters\"\n | \"user_created\"\n | \"support_queue\"\n | \"session_summaries\"\n | \"signal_report\"\n | \"slack\";\n signal_report?: string | null; // Inbox report UUID when origin_product is \"signal_report\"\n github_integration?: number | null;\n repository: string; // Format: \"organization/repository\" (e.g., \"posthog/posthog-js\")\n json_schema?: Record<string, unknown> | null; // JSON schema for task output validation\n internal?: boolean;\n created_at: string;\n updated_at: string;\n created_by?: {\n id: number;\n uuid: string;\n distinct_id: string;\n first_name: string;\n email: string;\n };\n latest_run?: TaskRun;\n}\n\n// Log entry structure for TaskRun.log\n\nexport type ArtifactType =\n | \"plan\"\n | \"context\"\n | \"reference\"\n | \"output\"\n | \"artifact\"\n | \"user_attachment\";\n\nexport interface TaskRunArtifact {\n id?: string;\n name: string;\n type: ArtifactType;\n source?: string;\n size?: number;\n content_type?: string;\n storage_path?: string;\n uploaded_at?: string;\n}\n\nexport type TaskRunStatus =\n | \"not_started\"\n | \"queued\"\n | \"in_progress\"\n | \"completed\"\n | \"failed\"\n | \"cancelled\";\n\nexport type TaskRunEnvironment = \"local\" | \"cloud\";\n\n// TaskRun model - represents individual execution runs of tasks\nexport interface TaskRun {\n id: string;\n task: string; // Task ID\n team: number;\n branch: string | null;\n stage: string | null; // Current stage (e.g., 'research', 'plan', 'build')\n environment: TaskRunEnvironment;\n status: TaskRunStatus;\n log_url: string;\n error_message: string | null;\n output: Record<string, unknown> | null; // Structured output (PR URL, commit SHA, etc.)\n state: Record<string, unknown>; // Intermediate run state (defaults to {}, never null)\n artifacts?: TaskRunArtifact[];\n created_at: string;\n updated_at: string;\n completed_at: string | null;\n}\n\nexport interface ProcessSpawnedCallback {\n onProcessSpawned?: (info: {\n pid: number;\n command: string;\n sessionId?: string;\n }) => void;\n onProcessExited?: (pid: number) => void;\n onMcpServersReady?: (serverNames: string[]) => void;\n}\n\nexport interface TaskExecutionOptions {\n repositoryPath?: string;\n adapter?: \"claude\" | \"codex\";\n model?: string;\n gatewayUrl?: string;\n codexBinaryPath?: string;\n instructions?: string;\n processCallbacks?: ProcessSpawnedCallback;\n /** Callback invoked when the agent calls the create_output tool for structured output */\n onStructuredOutput?: (output: Record<string, unknown>) => Promise<void>;\n /** Additional directories the agent process can access beyond cwd. */\n additionalDirectories?: string[];\n}\n\nexport type LogLevel = \"debug\" | \"info\" | \"warn\" | \"error\";\n\nexport type OnLogCallback = (\n level: LogLevel,\n scope: string,\n message: string,\n data?: unknown,\n) => void;\n\nexport interface PostHogAPIConfig {\n apiUrl: string;\n getApiKey: () => string | Promise<string>;\n refreshApiKey?: () => string | Promise<string>;\n projectId: number;\n userAgent?: string;\n}\n\nexport interface OtelTransportConfig {\n /** PostHog ingest host, e.g., \"https://us.i.posthog.com\" */\n host: string;\n /** Project API key */\n apiKey: string;\n /** Override the logs endpoint path (default: /i/v1/logs) */\n logsPath?: string;\n}\n\nexport interface AgentConfig {\n posthog?: PostHogAPIConfig;\n /** OTEL transport config for shipping logs to PostHog Logs */\n otelTransport?: OtelTransportConfig;\n /** Skip session log persistence (e.g. for preview sessions with no real task) */\n skipLogPersistence?: boolean;\n /** Local cache path for instant log loading (e.g., ~/.posthog-code) */\n localCachePath?: string;\n /**\n * Annotate files the agent reads with PostHog enrichment (event volume,\n * flag rollout/staleness, experiment links). Defaults to enabled when\n * `posthog` config is present; set `{ enabled: false }` to opt out.\n */\n enricher?: { enabled?: boolean };\n debug?: boolean;\n onLog?: OnLogCallback;\n}\n\n// Device info for tracking where work happens\nexport interface DeviceInfo {\n type: \"local\" | \"cloud\";\n name?: string;\n}\n\n// Agent execution mode - for tracking interactive vs background runs, when backgrounded an agent will continue working without asking questions\nexport type AgentMode = \"interactive\" | \"background\";\n\n// Git file status codes\nexport type FileStatus = \"A\" | \"M\" | \"D\";\n\nexport interface FileChange {\n path: string;\n status: FileStatus;\n}\n\nexport type HandoffLocalGitState = GitHandoffLocalGitState;\n\nexport interface GitCheckpoint extends GitHandoffCheckpoint {\n artifactPath?: string;\n indexArtifactPath?: string;\n}\n\nexport interface GitCheckpointEvent extends GitCheckpoint {\n device?: DeviceInfo;\n}\n\n/**\n * Keeps the emitted `@posthog/agent/types` entrypoint as a runtime ESM module.\n *\n * `export {}` is stripped by tsup in this package, which leaves `dist/types.js`\n * empty and breaks downstream type resolution for the exported subpath.\n */\nexport const AGENT_TYPES_MODULE = true;\n"],"mappings":";AAmNO,IAAM,qBAAqB;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
|
2
|
+
import type { Task } from "../types";
|
|
2
3
|
import { AgentServer } from "./agent-server";
|
|
3
4
|
|
|
4
5
|
interface TestableServer {
|
|
5
6
|
configureEnvironment(args?: {
|
|
6
7
|
isInternal?: boolean;
|
|
7
|
-
originProduct?:
|
|
8
|
+
originProduct?: Task["origin_product"] | null;
|
|
8
9
|
signalReportId?: string | null;
|
|
9
10
|
taskId?: string | null;
|
|
10
11
|
taskRunId?: string | null;
|
|
@@ -162,6 +163,43 @@ describe("AgentServer.configureEnvironment", () => {
|
|
|
162
163
|
);
|
|
163
164
|
});
|
|
164
165
|
|
|
166
|
+
it("tags as slack_app when the task was initiated from Slack", () => {
|
|
167
|
+
buildServer("interactive").configureEnvironment({
|
|
168
|
+
originProduct: "slack",
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
expect(process.env.LLM_GATEWAY_URL).toBe(
|
|
172
|
+
"https://gateway.us.posthog.com/slack_app",
|
|
173
|
+
);
|
|
174
|
+
expect(process.env.ANTHROPIC_BASE_URL).toBe(
|
|
175
|
+
"https://gateway.us.posthog.com/slack_app",
|
|
176
|
+
);
|
|
177
|
+
expect(process.env.OPENAI_BASE_URL).toBe(
|
|
178
|
+
"https://gateway.us.posthog.com/slack_app/v1",
|
|
179
|
+
);
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
it("prefers slack_app over background_agents when both signals are present", () => {
|
|
183
|
+
buildServer("interactive").configureEnvironment({
|
|
184
|
+
isInternal: true,
|
|
185
|
+
originProduct: "slack",
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
expect(process.env.LLM_GATEWAY_URL).toBe(
|
|
189
|
+
"https://gateway.us.posthog.com/slack_app",
|
|
190
|
+
);
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
it("falls back to posthog_code for non-slack origin products", () => {
|
|
194
|
+
buildServer("background").configureEnvironment({
|
|
195
|
+
originProduct: "user_created",
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
expect(process.env.LLM_GATEWAY_URL).toBe(
|
|
199
|
+
"https://gateway.us.posthog.com/posthog_code",
|
|
200
|
+
);
|
|
201
|
+
});
|
|
202
|
+
|
|
165
203
|
it("respects the LLM_GATEWAY_URL override regardless of internal flag", () => {
|
|
166
204
|
process.env.LLM_GATEWAY_URL = "http://ngrok.test/proxy";
|
|
167
205
|
|
|
@@ -43,6 +43,7 @@ import type {
|
|
|
43
43
|
GitCheckpointEvent,
|
|
44
44
|
HandoffLocalGitState,
|
|
45
45
|
LogLevel,
|
|
46
|
+
Task,
|
|
46
47
|
TaskRun,
|
|
47
48
|
TaskRunArtifact,
|
|
48
49
|
} from "../types";
|
|
@@ -1860,7 +1861,7 @@ ${signedCommitInstructions}
|
|
|
1860
1861
|
taskUserId,
|
|
1861
1862
|
}: {
|
|
1862
1863
|
isInternal?: boolean;
|
|
1863
|
-
originProduct?:
|
|
1864
|
+
originProduct?: Task["origin_product"] | null;
|
|
1864
1865
|
signalReportId?: string | null;
|
|
1865
1866
|
taskId?: string | null;
|
|
1866
1867
|
taskRunId?: string | null;
|
package/src/types.ts
CHANGED
|
@@ -38,7 +38,8 @@ export interface Task {
|
|
|
38
38
|
| "user_created"
|
|
39
39
|
| "support_queue"
|
|
40
40
|
| "session_summaries"
|
|
41
|
-
| "signal_report"
|
|
41
|
+
| "signal_report"
|
|
42
|
+
| "slack";
|
|
42
43
|
signal_report?: string | null; // Inbox report UUID when origin_product is "signal_report"
|
|
43
44
|
github_integration?: number | null;
|
|
44
45
|
repository: string; // Format: "organization/repository" (e.g., "posthog/posthog-js")
|
package/src/utils/gateway.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
export type GatewayProduct =
|
|
1
|
+
export type GatewayProduct =
|
|
2
|
+
| "posthog_code"
|
|
3
|
+
| "background_agents"
|
|
4
|
+
| "signals"
|
|
5
|
+
| "slack_app";
|
|
2
6
|
|
|
3
7
|
export function resolveGatewayProduct({
|
|
4
8
|
isInternal,
|
|
@@ -7,6 +11,9 @@ export function resolveGatewayProduct({
|
|
|
7
11
|
isInternal?: boolean;
|
|
8
12
|
originProduct?: string | null;
|
|
9
13
|
} = {}): GatewayProduct {
|
|
14
|
+
if (originProduct === "slack") {
|
|
15
|
+
return "slack_app";
|
|
16
|
+
}
|
|
10
17
|
if (isInternal) {
|
|
11
18
|
return originProduct === "signal_report" ? "signals" : "background_agents";
|
|
12
19
|
}
|