mirror of
https://github.com/AmruthPillai/Reactive-Resume.git
synced 2026-07-25 17:34:52 +10:00
feat: add AI agent workspace (#3062)
* chore(ai): remove local AI store now that providers live server-side
The Zustand-based useAIStore has been replaced by the server-side
aiProviders oRPC router (encrypted credentials persisted in DB).
Delete the dead store + tests, drop the ./store export, and remove
zustand/immer deps which are no longer referenced anywhere in
packages/ai/src/.
* feat(agent): archive/delete actions and read-only state for agent threads
- Backend: mark archived threads as read-only in threads.get and reject
messages.send with CONFLICT when the thread is archived.
- Frontend: render archived threads in the sidebar with muted styling and
an Archived badge; add a per-thread dropdown menu in the chat header
with Archive (non-destructive) and Delete (with confirmation); show a
read-only banner above the message list that disambiguates archived
vs. missing-resource causes; suppress the Retry and Stop buttons in
read-only mode.
- Tests: new packages/api/src/services/agent.test.ts covering the
archived-thread isReadOnly flag and the archived-thread send refusal.
* fix(agent): abort run on archive and verify ownership before deleting thread
- threads.archive: before flipping status, abort any in-flight run controller
and clear the active-run state on the thread; cleanup failures are logged
but do not block the status update.
- threads.delete: assert thread ownership via getThread before destructive
work so an authenticated user cannot wipe another user's attachment rows
by passing a foreign threadId.
Adds focused tests for both behaviors.
* feat(agent): display patch diffs and surface revert conflicts
Render apply_resume_patch tool messages with a status-aware card (applied/
reverted/conflicted), expandable operation list, and a Revert button that
correctly handles RESUME_VERSION_CONFLICT responses. Adds unit tests for
the inverse-patch builder and the agentService.actions.revert flow.
* chore(agent): remove out-of-scope attachment tests accidentally added in Task 6
The Task 6 commit (73ef1acca) accidentally re-introduced three attachment-
related tests that belong to a separate task:
- `buildAttachmentModelParts > converts text, image, supported binary, and
unsupported attachments into model parts`
- `agentService.messages.send > persists the user message with file UI parts
and links selected attachments to it` (was failing — the `ToolLoopAgent`
mock is not callable as a constructor)
- `agentService.messages.send > rejects attachments that are missing, foreign,
or already linked before persisting a message`
These were likely re-added during a stash recovery and were not requested
for Task 6, whose scope was limited to the `agentService.actions.revert`
flow. Remove them along with the helpers/fixtures (`buildAttachment`,
`buildActiveThread`, `selectWhereResult`, `selectOrderByResult`) that they
were the only consumers of. `selectLimitResult` is preserved because it is
used by the revert tests.
* chore(agent): configure runtime dependencies
* feat(db): add agent workspace schema
* feat(api): add agent backend services
* feat(web): add agent workspace UI
* chore(agent): remove legacy builder assistant
* test(agent): make agent stream mocks constructible
* chore(web): remove unused resume replacement hook
* feat(api): add unsafe AI base URL flag
* chore(dev): expose local services in compose
* fix(web): normalize resume preview gaps
* feat(api): improve agent tool handling
* feat(web): polish agent workspace UI
* chore: update dependencies
* fix(api,web): address PR review feedback for agent workspace
Security/correctness:
- Restrict AI provider URLs to http/https even in unsafe mode
- Stop exposing Redis on host network by default
- Make .env.local optional and drop app profile in compose.dev.yml
- Store agent attachments with private ACL on S3
- Reset provider test status when provider/model/baseURL changes
- Decouple non-agent AI endpoints from REDIS_URL requirement
- Fix JSON Patch add inverse for existing object members
- Wrap resume patch + agent action insert in db transaction
- Validate partialMessage at runtime and rate-limit attachment uploads
- Add unique index on agent_messages (thread_id, sequence)
UX/bugs:
- Mark agent thread route as ssr: false and guard SSE chunk parsing
- Show config-specific banner only on known configuration error
- Gate AI provider checks behind loading state in resume import
- Fix relative-time formatter blank gap between 45-59 seconds
- Clarify thread delete confirmation message
Polish:
- Raise ENCRYPTION_SECRET minimum to 32 characters
- Bucket AI rate limits by resumeId/threadId/messageId
- Trim form values before submitting AI provider config
- Use single key identifier and nullish-coalesce baseURL display
* fix: address ai agent review feedback
* fix: preserve mobile agent chat state
* docs: add ai agent workspace guides
* feat: introduce design system for Reactive Resume
This commit is contained in:
@@ -1,123 +0,0 @@
|
||||
// @vitest-environment happy-dom
|
||||
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
import { useAIStore } from "./store";
|
||||
|
||||
const reset = () => {
|
||||
useAIStore.setState({
|
||||
enabled: false,
|
||||
provider: "openai",
|
||||
model: "",
|
||||
apiKey: "",
|
||||
baseURL: "",
|
||||
testStatus: "unverified",
|
||||
});
|
||||
};
|
||||
|
||||
afterEach(reset);
|
||||
|
||||
describe("useAIStore", () => {
|
||||
it("starts with provider=openai and disabled state", () => {
|
||||
const state = useAIStore.getState();
|
||||
expect(state.enabled).toBe(false);
|
||||
expect(state.provider).toBe("openai");
|
||||
expect(state.testStatus).toBe("unverified");
|
||||
});
|
||||
|
||||
it("set() updates fields and resets verification when credential fields change", () => {
|
||||
useAIStore.setState({ testStatus: "success", enabled: true });
|
||||
|
||||
useAIStore.getState().set((draft) => {
|
||||
draft.apiKey = "new-key";
|
||||
});
|
||||
|
||||
const state = useAIStore.getState();
|
||||
expect(state.apiKey).toBe("new-key");
|
||||
expect(state.testStatus).toBe("unverified");
|
||||
expect(state.enabled).toBe(false);
|
||||
});
|
||||
|
||||
it("set() does NOT reset testStatus when changing non-credential fields", () => {
|
||||
useAIStore.setState({ testStatus: "success", enabled: true });
|
||||
|
||||
useAIStore.getState().set((draft) => {
|
||||
draft.testStatus = "success"; // explicit no-op
|
||||
});
|
||||
|
||||
const state = useAIStore.getState();
|
||||
expect(state.testStatus).toBe("success");
|
||||
expect(state.enabled).toBe(true);
|
||||
});
|
||||
|
||||
it("canEnable() is true only when testStatus is success", () => {
|
||||
expect(useAIStore.getState().canEnable()).toBe(false);
|
||||
|
||||
useAIStore.setState({ testStatus: "success" });
|
||||
expect(useAIStore.getState().canEnable()).toBe(true);
|
||||
|
||||
useAIStore.setState({ testStatus: "failure" });
|
||||
expect(useAIStore.getState().canEnable()).toBe(false);
|
||||
});
|
||||
|
||||
it("setEnabled(true) refuses to enable when testStatus is not success", () => {
|
||||
useAIStore.getState().setEnabled(true);
|
||||
expect(useAIStore.getState().enabled).toBe(false);
|
||||
});
|
||||
|
||||
it("setEnabled(true) succeeds when testStatus is success", () => {
|
||||
useAIStore.setState({ testStatus: "success" });
|
||||
useAIStore.getState().setEnabled(true);
|
||||
expect(useAIStore.getState().enabled).toBe(true);
|
||||
});
|
||||
|
||||
it("setEnabled(false) always succeeds (regardless of testStatus)", () => {
|
||||
useAIStore.setState({ testStatus: "success", enabled: true });
|
||||
useAIStore.getState().setEnabled(false);
|
||||
expect(useAIStore.getState().enabled).toBe(false);
|
||||
});
|
||||
|
||||
it("reset() clears every field back to initial state", () => {
|
||||
useAIStore.setState({
|
||||
enabled: true,
|
||||
provider: "anthropic",
|
||||
model: "claude-3",
|
||||
apiKey: "key",
|
||||
baseURL: "https://api.anthropic.com",
|
||||
testStatus: "success",
|
||||
});
|
||||
|
||||
useAIStore.getState().reset();
|
||||
|
||||
const state = useAIStore.getState();
|
||||
expect(state).toMatchObject({
|
||||
enabled: false,
|
||||
provider: "openai",
|
||||
model: "",
|
||||
apiKey: "",
|
||||
baseURL: "",
|
||||
testStatus: "unverified",
|
||||
});
|
||||
});
|
||||
|
||||
it("resets when only the provider changes", () => {
|
||||
useAIStore.setState({ testStatus: "success", enabled: true });
|
||||
|
||||
useAIStore.getState().set((draft) => {
|
||||
draft.provider = "gemini";
|
||||
});
|
||||
|
||||
expect(useAIStore.getState().testStatus).toBe("unverified");
|
||||
expect(useAIStore.getState().enabled).toBe(false);
|
||||
});
|
||||
|
||||
it("resets when only the baseURL changes", () => {
|
||||
useAIStore.setState({ testStatus: "success", enabled: true });
|
||||
|
||||
useAIStore.getState().set((draft) => {
|
||||
draft.baseURL = "https://custom.example";
|
||||
});
|
||||
|
||||
expect(useAIStore.getState().testStatus).toBe("unverified");
|
||||
expect(useAIStore.getState().enabled).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -1,88 +0,0 @@
|
||||
import type { WritableDraft } from "immer";
|
||||
import type { AIProvider } from "./types";
|
||||
import { createJSONStorage, persist } from "zustand/middleware";
|
||||
import { immer } from "zustand/middleware/immer";
|
||||
import { create } from "zustand/react";
|
||||
|
||||
type TestStatus = "unverified" | "success" | "failure";
|
||||
|
||||
type AIStoreState = {
|
||||
enabled: boolean;
|
||||
provider: AIProvider;
|
||||
model: string;
|
||||
apiKey: string;
|
||||
baseURL: string;
|
||||
testStatus: TestStatus;
|
||||
};
|
||||
|
||||
type AIStoreActions = {
|
||||
canEnable: () => boolean;
|
||||
setEnabled: (value: boolean) => void;
|
||||
set: (fn: (draft: WritableDraft<AIStoreState>) => void) => void;
|
||||
reset: () => void;
|
||||
};
|
||||
|
||||
type AIStore = AIStoreState & AIStoreActions;
|
||||
|
||||
const initialState: AIStoreState = {
|
||||
enabled: false,
|
||||
provider: "openai",
|
||||
model: "",
|
||||
apiKey: "",
|
||||
baseURL: "",
|
||||
testStatus: "unverified",
|
||||
};
|
||||
|
||||
export const useAIStore = create<AIStore>()(
|
||||
persist(
|
||||
immer((set, get) => ({
|
||||
...initialState,
|
||||
set: (fn) => {
|
||||
set((draft) => {
|
||||
const prev = {
|
||||
provider: draft.provider,
|
||||
model: draft.model,
|
||||
apiKey: draft.apiKey,
|
||||
baseURL: draft.baseURL,
|
||||
};
|
||||
|
||||
fn(draft);
|
||||
|
||||
if (
|
||||
draft.provider !== prev.provider ||
|
||||
draft.model !== prev.model ||
|
||||
draft.apiKey !== prev.apiKey ||
|
||||
draft.baseURL !== prev.baseURL
|
||||
) {
|
||||
draft.testStatus = "unverified";
|
||||
draft.enabled = false;
|
||||
}
|
||||
});
|
||||
},
|
||||
reset: () => set(() => initialState),
|
||||
canEnable: () => {
|
||||
const { testStatus } = get();
|
||||
return testStatus === "success";
|
||||
},
|
||||
setEnabled: (value: boolean) => {
|
||||
const canEnable = get().canEnable();
|
||||
if (value && !canEnable) return;
|
||||
set((draft) => {
|
||||
draft.enabled = value;
|
||||
});
|
||||
},
|
||||
})),
|
||||
{
|
||||
name: "ai-store",
|
||||
storage: createJSONStorage(() => localStorage),
|
||||
partialize: (state) => ({
|
||||
enabled: state.enabled,
|
||||
provider: state.provider,
|
||||
model: state.model,
|
||||
apiKey: state.apiKey,
|
||||
baseURL: state.baseURL,
|
||||
testStatus: state.testStatus,
|
||||
}),
|
||||
},
|
||||
),
|
||||
);
|
||||
@@ -1,6 +1,14 @@
|
||||
import { z } from "zod";
|
||||
|
||||
const AI_PROVIDERS = ["openai", "anthropic", "gemini", "vercel-ai-gateway", "openrouter", "ollama"] as const;
|
||||
const AI_PROVIDERS = [
|
||||
"openai",
|
||||
"anthropic",
|
||||
"gemini",
|
||||
"vercel-ai-gateway",
|
||||
"openrouter",
|
||||
"ollama",
|
||||
"openai-compatible",
|
||||
] as const;
|
||||
|
||||
export type AIProvider = (typeof AI_PROVIDERS)[number];
|
||||
|
||||
@@ -13,4 +21,5 @@ export const AI_PROVIDER_DEFAULT_BASE_URLS: Record<AIProvider, string> = {
|
||||
"vercel-ai-gateway": "https://ai-gateway.vercel.sh/v3/ai",
|
||||
openrouter: "https://openrouter.ai/api/v1",
|
||||
ollama: "https://ollama.com/api",
|
||||
"openai-compatible": "",
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user