rowboat/apps/x/packages/shared/src/service-events.ts
arkml d191c00e4d
Memory2 (#444)
Agent Notes: background memory system that learns from emails, chats, and explicit
  saves

  - Background service (agent_notes.ts) runs periodically, collecting user-sent
  emails, copilot conversation history, and save-to-memory inbox entries
  - Agent (agent_notes_agent.ts) processes all sources with workspace tools, deciding
  what to update: user.md (timestamped facts), preferences.md (general rules),
  style/email.md (writing patterns), and topic-specific files as needed
  - save-to-memory builtin tool lets the copilot proactively note preferences during
  conversations
  - user.md and preferences.md injected into copilot system prompt on every turn;
  other files listed for on-demand access
  - Agent manages timestamp freshness on user.md: refreshes confirmed facts, removes
  stale transient ones
2026-03-23 22:30:02 +05:30

68 lines
1.9 KiB
TypeScript

import z from 'zod';
export const ServiceName = z.enum([
'graph',
'gmail',
'calendar',
'fireflies',
'granola',
'voice_memo',
'email_labeling',
'note_tagging',
'agent_notes',
]);
const ServiceEventBase = z.object({
service: ServiceName,
runId: z.string(),
ts: z.iso.datetime(),
level: z.enum(['info', 'warn', 'error']),
message: z.string(),
});
export const ServiceRunStartEvent = ServiceEventBase.extend({
type: z.literal('run_start'),
trigger: z.enum(['timer', 'manual', 'startup']).optional(),
config: z.record(z.string(), z.unknown()).optional(),
});
export const ServiceChangesIdentifiedEvent = ServiceEventBase.extend({
type: z.literal('changes_identified'),
counts: z.record(z.string(), z.number()).optional(),
items: z.array(z.string()).optional(),
truncated: z.boolean().optional(),
});
export const ServiceProgressEvent = ServiceEventBase.extend({
type: z.literal('progress'),
step: z.string().optional(),
current: z.number().optional(),
total: z.number().optional(),
details: z.record(z.string(), z.unknown()).optional(),
});
export const ServiceRunCompleteEvent = ServiceEventBase.extend({
type: z.literal('run_complete'),
durationMs: z.number(),
outcome: z.enum(['ok', 'idle', 'skipped', 'error']),
summary: z.record(z.string(), z.union([z.string(), z.number(), z.boolean()])).optional(),
items: z.array(z.string()).optional(),
truncated: z.boolean().optional(),
});
export const ServiceErrorEvent = ServiceEventBase.extend({
type: z.literal('error'),
error: z.string(),
context: z.record(z.string(), z.unknown()).optional(),
});
export const ServiceEvent = z.union([
ServiceRunStartEvent,
ServiceChangesIdentifiedEvent,
ServiceProgressEvent,
ServiceRunCompleteEvent,
ServiceErrorEvent,
]);
export type ServiceNameType = z.infer<typeof ServiceName>;
export type ServiceEventType = z.infer<typeof ServiceEvent>;