AkurAI Build
Menu

popagent

public

Latest change 682410a285bb0a73662cc4650c92c31c918e1cc9 - Add idle autonomous improvement workflow by Ólafur Búi Ólafsson

export const MAX_AGENT_INSTRUCTIONS_CHARACTERS = 32_000;
export const DEFAULT_WORKSPACE_ID = "default";

export type ChatMessage = {
  id: string;
  role: string;
  parts: unknown[];
  metadata?: Record<string, unknown>;
  [key: string]: unknown;
};
export type AgentActivity = {
  turnId: string;
  runId: string;
  agentId: string;
  agentName: string;
  iteration: number;
  maxIterations: number | null;
  isFinal: boolean;
  finishReason: string;
  text: string;
  tools: string[];
};

export type AgentWorkspace = {
  id: string;
  name: string;
  repositoryPath: string;
  createdAt: string;
  updatedAt: string;
};

export type DocumentationFolder = {
  path: string;
  name: string;
  updatedAt: string;
};

export type DocumentationPageSummary = {
  path: string;
  title: string;
  revision: string;
  size: number;
  updatedAt: string;
};
export type DocumentationPage = DocumentationPageSummary & { content: string };
export type DocumentationSearchResult = {
  workspaceId: string;
  workspaceName: string;
  path: string;
  title: string;
  heading?: string;
  excerpt: string;
  score: number;
};
export type DocumentationIndexStatus = {
  workspaceId: string;
  files: number;
  chunks: number;
  indexedAt: string | null;
  model: string;
  dimension: number;
  running: boolean;
};
export type DocumentationListResponse = {
  folders: DocumentationFolder[];
  pages: DocumentationPageSummary[];
};
export type DocumentationSearchResponse = { results: DocumentationSearchResult[] };

export type SessionSummary = {
  id: string;
  title: string;
  model: string;
  workspaceId: string;
  revision: number;
  archivedAt: string | null;
  createdAt: string;
  updatedAt: string;
};

export type Session<Message = ChatMessage> = SessionSummary & { messages: Message[] };
export const AGENT_TOOL_NAMES = [
  "getTime",
  "retainMemory",
  "recallMemory",
  "reflectMemory",
  "editMemory",
  "useBrowserSecret",
  "bifrostNavigator",
  "webSearch",
  "searchDocumentation",
] as const;
export type AgentToolName = (typeof AGENT_TOOL_NAMES)[number];
export type AgentWorkspaceAccess = "read-write" | "read-only" | "none";
export type AgentBrowserAccess = "interactive" | "read-only" | "none";

export type AgentSettings = {
  id: string;
  name: string;
  description: string;
  instructions: string;
  model: string | null;
  workspaceAccess: AgentWorkspaceAccess;
  browserAccess: AgentBrowserAccess;
  delegationEnabled: boolean;
  tools: AgentToolName[];
  sourceUrls: string[];
  createdAt: string;
  updatedAt: string;
};

export type AgentSettingsInput = Pick<
  AgentSettings,
  | "name"
  | "description"
  | "instructions"
  | "model"
  | "workspaceAccess"
  | "browserAccess"
  | "delegationEnabled"
  | "tools"
>;

export type AgentSecret = {
  name: string;
  allowedOrigin: string | null;
  createdAt: string;
  updatedAt: string;
};

export type AgentSecretInput = {
  name: string;
  value: string;
  allowedOrigin: string;
};

export type AgentSecretUpdateInput = {
  value?: string;
  allowedOrigin?: string;
};

export type AgentSecretListResponse = { secrets: AgentSecret[] };

export type AgentSkill = {
  id: string;
  agentId: string;
  name: string;
  description: string;
  instructions: string;
  references: Record<string, string>;
  sourceUrls: string[];
  enabled: boolean;
  userInvocable: boolean;
  evolutionManaged: boolean;
  createdAt: string;
  updatedAt: string;
};

export type AgentSkillInput = Pick<
  AgentSkill,
  "name" | "description" | "instructions" | "references" | "enabled" | "userInvocable"
>;

export type ChannelDispatchMode = "every-message" | "mentions";
export type ChannelToolDisplay = "compact" | "timeline";

export type ChannelSettings = {
  enabled: boolean;
  channelName: string;
  dispatchMode: ChannelDispatchMode;
  contextMessages: number;
  streaming: boolean;
  toolDisplay: ChannelToolDisplay;
  updatedAt: string;
};

export type ChannelSettingsInput = Omit<ChannelSettings, "updatedAt">;

export type Channel = {
  id: string;
  name: string;
  createdAt: string;
  updatedAt: string;
};

export type ChannelMessage = {
  id: string;
  channelId: string;
  workspaceId: string;
  authorId: string;
  authorName: string;
  content: string;
  taskId: string | null;
  task: AgentTask | null;
  createdAt: string;
};

export type ChannelEvent = {
  id: string;
  channelId: string;
  type: "message" | "task" | "settings";
  messageId: string | null;
  taskId: string | null;
  taskStatus: AgentTaskStatus | null;
  createdAt: string;
};

export type ChannelPostResponse = { message: ChannelMessage; task: AgentTask | null };

export type BrowserScope = "thread" | "shared";

export type BrowserSettings = {
  enabled: boolean;
  scope: BrowserScope;
  viewportWidth: number;
  viewportHeight: number;
  timeoutMs: number;
  maxSessions: number;
  idleTimeoutMs: number;
  screencastEnabled: boolean;
  screenshotsEnabled: boolean;
  multiTabEnabled: boolean;
  formsEnabled: boolean;
  dialogsEnabled: boolean;
  dragEnabled: boolean;
  evaluateEnabled: boolean;
  recordingEnabled: boolean;
  recordingRetentionDays: number;
  recordingMaxFiles: number;
  allowHosts: string[];
  denyHosts: string[];
  updatedAt: string;
};

export type BrowserSettingsInput = Omit<BrowserSettings, "updatedAt">;

export type BrowserProfile = {
  id: string;
  name: string;
  enabled: boolean;
  createdAt: string;
  updatedAt: string;
};

export type BrowserSession = {
  id: string;
  threadId: string;
  access: "interactive" | "read-only";
  status: "active" | "closed" | "error";
  currentUrl: string | null;
  tabs: Array<{ id: string; url: string; title: string }>;
  activeTabIndex: number;
  createdAt: string;
  lastActivityAt: string;
};

export type MemoryActivationMode = "off" | "auto" | "5m" | "1hr" | "24hr";
export type MemoryAttachmentPolicy = "auto" | "all" | "none";

export type MemorySettings = {
  autoCompact: boolean;
  observationTokens: number;
  reflectionTokens: number;
  recentMessagePercent: number;
  asyncBuffering: boolean;
  bufferIntervalPercent: number;
  bufferOnIdle: boolean;
  observationBlockPercent: number;
  reflectionBufferPercent: number;
  reflectionBlockPercent: number;
  optimizeObserverContext: boolean;
  previousObserverTokens: number;
  retrievalEnabled: boolean;
  retrievalScope: "thread" | "resource";
  temporalMarkers: boolean;
  activateAfterIdle: MemoryActivationMode;
  activateOnProviderChange: boolean;
  shareTokenBudget: boolean;
  observeAttachments: MemoryAttachmentPolicy;
  observationInstruction: string;
  reflectionInstruction: string;
  internalRecall: boolean;
  internalRetention: boolean;
  updatedAt: string;
};

export type MemorySettingsInput = Omit<MemorySettings, "updatedAt">;

export type AgentRuntimeSettings = {
  defaultModel: string;
  supervisorMaxSteps: number;
  specialistMaxSteps: number;
  toolConcurrency: number;
  delegationContextMessages: number;
  delegationResultCharacters: number;
  maxProcessorRetries: number;
  finalResponseFeedback: string;
  delegationFailureFeedback: string;
  delegationResultTruncationMarker: string;
  taskConcurrency: number;
  taskPollIntervalMs: number;
  taskTimeoutMs: number;
  taskStaleAfterMs: number;
  updatedAt: string;
};

export type AgentRuntimeSettingsInput = Omit<AgentRuntimeSettings, "updatedAt">;

export type AutonomySettings = {
  enabled: boolean;
  reflectionIntervalMs: number;
  batchSize: number;
  maxAttempts: number;
  autoApplyStrategies: boolean;
  autoCreateSkills: boolean;
  selfUpdateEnabled: boolean;
  selfUpdateCron: string;
  idleImprovementEnabled: boolean;
  idleDeploymentEnabled: boolean;
  idleGraceMs: number;
  idleWorkspaceIds: string[];
  lastUserActivityAt: string;
  updatedAt: string;
};

export type AutonomySettingsInput = Omit<AutonomySettings, "updatedAt" | "lastUserActivityAt">;

export type AutomationStatus = {
  state: "active" | "idle-grace" | "eligible" | "improving" | "paused";
  lastUserActivityAt: string;
  eligibleAt: string;
  activeTask: AgentTask | null;
  selectedWorkspaceIds: string[];
};

export type EvolutionSignal = {
  id: string;
  sessionId: string | null;
  turnId: string | null;
  traceId: string | null;
  agentId: string;
  workspaceId: string | null;
  kind: "turn-success" | "turn-failure";
  summary: string;
  status: "pending" | "processing" | "applied" | "ignored" | "dead-letter";
  attempts: number;
  nextAttemptAt: string | null;
  processedAt: string | null;
  error: string | null;
  createdAt: string;
  updatedAt: string;
};

export type EvolutionRevision = {
  id: string;
  agentId: string;
  targetType: "overlay" | "skill";
  targetKey: string;
  beforeContent: string | null;
  afterContent: string | null;
  rationale: string;
  evidenceIds: string[];
  status: "applied" | "reverted";
  revertsRevisionId: string | null;
  createdAt: string;
  appliedAt: string;
};

export type EvolutionSignalListResponse = { signals: EvolutionSignal[] };
export type EvolutionRevisionListResponse = { revisions: EvolutionRevision[] };

export type MemoryRecord = {
  id: string;
  resourceId: string;
  sessionId: string;
  kind: "fact" | "episode";
  key: string | null;
  content: string;
  importance: number;
  accessCount: number;
  createdAt: string;
  updatedAt: string;
  lastAccessedAt: string;
};

export type MemoryStatus = {
  facts: number;
  episodes: number;
  recalled: number;
  latestUpdatedAt: string | null;
};

export type AgentTaskStatus = "queued" | "running" | "cancelling" | "completed" | "failed" | "cancelled" | "dead-letter";
export type AgentTaskSource = "user" | "self-update";
export type AgentExecutionSource = "chat" | "task" | "schedule" | "self-update";



export type AgentTaskErrorClass =
  | "timeout"
  | "provider"
  | "rate-limit"
  | "browser"
  | "database"
  | "infrastructure"
  | "cancelled"
  | "hook-denial"
  | "validation"
  | "permission"
  | "configuration"
  | "restart-stale"
  | "unknown";

export type AgentTask = {
  id: string;
  sessionId: string | null;
  scheduleId: string | null;
  source: AgentTaskSource;
  workspaceId: string;
  prompt: string;
  model: string;
  status: AgentTaskStatus;
  output: string | null;
  error: string | null;
  stepsCompleted: number;
  progress: string | null;
  recoveryCount: number;
  attemptCount: number;
  maxAttempts: number;
  nextAttemptAt: string | null;
  lastErrorClass: AgentTaskErrorClass | null;
  deadLetteredAt: string | null;
  heartbeatAt?: string | null;
  createdAt: string;
  startedAt: string | null;
  completedAt: string | null;
};

export type AgentTaskProgress = Pick<AgentTask, "stepsCompleted" | "progress">;

export type AgentSchedule = {
  id: string;
  sessionId: string | null;
  workspaceId: string;
  source: AgentTaskSource;
  name: string;
  prompt: string;
  model: string;
  maxAttempts: number;
  cron: string;
  timezone: string;
  enabled: boolean;
  nextRunAt: string | null;
  lastRunAt: string | null;
  latestTaskStatus?: AgentTaskStatus | null;
  latestHeartbeatAt?: string | null;
  createdAt: string;
  updatedAt: string;
};

export type HookRunStatus =
  | "passed"
  | "modified"
  | "denied"
  | "continued"
  | "failed-open"
  | "failed-closed";

export type HookAuditRun = {
  id: string;
  eventId: string;
  sessionId: string;
  turnId: string | null;
  toolCallId: string | null;
  eventName: string;
  handlerId: string;
  startedAt: string;
  completedAt: string;
  durationMs: number;
  status: HookRunStatus;
  reason: string | null;
  error: string | null;
};

export type ModelCatalog = {
  models: string[];
  contextWindows: Record<string, number>;
};

export type ModelCatalogResponse = ModelCatalog & { defaultModel: string };

export type ChannelListResponse = { channels: Channel[] };
export type ChannelMessageListResponse = { messages: ChannelMessage[]; nextCursor?: string | null };
export type WorkspaceListResponse = { workspaces: AgentWorkspace[] };
export type WorkspaceChatDeleteResponse = { deleted: number };
export type AgentListResponse = { agents: AgentSettings[] };
export type AgentSkillListResponse = { skills: AgentSkill[] };
export type MemoryListResponse = { memories: MemoryRecord[] };
export type TaskListResponse = { tasks: AgentTask[] };
export type ScheduleListResponse = { schedules: AgentSchedule[] };
export type SessionListResponse = { sessions: SessionSummary[] };
export type HookRunListResponse = { runs: HookAuditRun[] };

export type ObservabilityTraceSummary = {
  traceId: string;
  name: string;
  entityName: string | null;
  status: "success" | "error" | "running";
  startedAt: string;
  endedAt: string | null;
  durationMs: number | null;
  tags: string[];
  metadata: Record<string, unknown>;
};

export type ObservabilityTraceSpan = ObservabilityTraceSummary & {
  spanId: string;
  parentSpanId: string | null;
  spanType: string;
  input: unknown;
  output: unknown;
  error: unknown;
};

export type ObservabilityOverviewResponse = {
  from: string;
  to: string;
  runs: number;
  errors: number;
  errorRate: number;
  p95LatencyMs: number | null;
  inputTokens: number;
  outputTokens: number;
  processRssBytes: number;
  processHeapUsedBytes: number;
};

export type ObservabilityTraceListResponse = {
  traces: ObservabilityTraceSummary[];
  page: number;
  perPage: number;
  total: number;
  hasMore: boolean;
};

export type ObservabilityTraceResponse = { traceId: string; spans: ObservabilityTraceSpan[] };

export type ObservabilityLog = {
  id: string | null;
  timestamp: string;
  level: "debug" | "info" | "warn" | "error" | "fatal";
  message: string;
  traceId: string | null;
  spanId: string | null;
  entityName: string | null;
  data: Record<string, unknown>;
};

export type ObservabilityLogListResponse = {
  logs: ObservabilityLog[];
  page: number;
  perPage: number;
  total: number;
  hasMore: boolean;
};

export type ObservabilityHealthResponse = {
  status: "ok" | "error";
  checkedAt: string;
  error?: string;
};