@starlein/paperclip-plugin-company-wizard 0.4.11 → 0.4.12

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/worker.js CHANGED
@@ -10563,6 +10563,14 @@ var PaperclipClient = class {
10563
10563
  body: JSON.stringify({ name, description: description || null })
10564
10564
  });
10565
10565
  }
10566
+ /**
10567
+ * List all companies the connected identity can see.
10568
+ * Returns the raw array from `GET /api/companies`.
10569
+ */
10570
+ async listCompanies() {
10571
+ const result = await this._fetch("/api/companies", { method: "GET" });
10572
+ return Array.isArray(result) ? result : result?.companies ?? [];
10573
+ }
10566
10574
  async updateCompany(companyId, updates) {
10567
10575
  return this._fetch(`/api/companies/${companyId}`, {
10568
10576
  method: "PATCH",
@@ -11003,7 +11011,7 @@ var __dirname = path2.dirname(fileURLToPath2(import.meta.url));
11003
11011
  var DEFAULT_TEMPLATES_REPO_URL = "https://github.com/starlein/paperclip-plugin-company-wizard/tree/main/templates";
11004
11012
  var BUNDLED_TEMPLATES_DIR = path2.resolve(__dirname, "..", "templates");
11005
11013
  var PLUGIN_PACKAGE_NAME = "@starlein/paperclip-plugin-company-wizard";
11006
- var CURRENT_PLUGIN_VERSION = "0.4.11";
11014
+ var CURRENT_PLUGIN_VERSION = "0.4.12";
11007
11015
  var NPM_LATEST_URL = "https://registry.npmjs.org/@starlein%2Fpaperclip-plugin-company-wizard/latest";
11008
11016
  function copyDirSync(src, dest) {
11009
11017
  fs2.mkdirSync(dest, { recursive: true });
@@ -11182,16 +11190,42 @@ function loadTemplates(templatesDir) {
11182
11190
  loadErrors: [...presetLoad.errors, ...moduleLoad.errors, ...roleLoad.errors]
11183
11191
  };
11184
11192
  }
11193
+ function resolvePaperclipCredentials(cfg) {
11194
+ return {
11195
+ url: cfg.paperclipUrl || process.env.PAPERCLIP_PUBLIC_URL || "http://localhost:3100",
11196
+ email: cfg.paperclipEmail || "",
11197
+ password: cfg.paperclipPassword || ""
11198
+ };
11199
+ }
11200
+ var sharedAuthCache = null;
11201
+ var SHARED_AUTH_TTL_MS = 5 * 60 * 1e3;
11202
+ async function connectSharedClient(cfg) {
11203
+ const { url, email, password } = resolvePaperclipCredentials(cfg);
11204
+ const key = `${url}|${email}`;
11205
+ const client = new PaperclipClient(url, { email, password });
11206
+ if (sharedAuthCache && sharedAuthCache.key === key && Date.now() - sharedAuthCache.ts < SHARED_AUTH_TTL_MS) {
11207
+ client.sessionCookie = sharedAuthCache.sessionCookie;
11208
+ client.boardUserId = sharedAuthCache.boardUserId;
11209
+ client.boardUserName = sharedAuthCache.boardUserName;
11210
+ client.boardUserEmail = sharedAuthCache.boardUserEmail;
11211
+ if (await client.ping()) {
11212
+ return client;
11213
+ }
11214
+ }
11215
+ await client.connect();
11216
+ sharedAuthCache = {
11217
+ key,
11218
+ ts: Date.now(),
11219
+ sessionCookie: client.sessionCookie,
11220
+ boardUserId: client.boardUserId,
11221
+ boardUserName: client.boardUserName,
11222
+ boardUserEmail: client.boardUserEmail
11223
+ };
11224
+ return client;
11225
+ }
11185
11226
  async function resolveEnableIsolatedWorkspacesFromInstance(cfg, log) {
11186
- const paperclipUrl = cfg.paperclipUrl || process.env.PAPERCLIP_PUBLIC_URL || "http://localhost:3100";
11187
- const paperclipEmail = cfg.paperclipEmail || "";
11188
- const paperclipPassword = cfg.paperclipPassword || "";
11189
- const instanceClient = new PaperclipClient(paperclipUrl, {
11190
- email: paperclipEmail,
11191
- password: paperclipPassword
11192
- });
11193
11227
  try {
11194
- await instanceClient.connect();
11228
+ const instanceClient = await connectSharedClient(cfg);
11195
11229
  const experimentalSettings = await instanceClient.getInstanceExperimentalSettings();
11196
11230
  return experimentalSettings?.enableIsolatedWorkspaces === true;
11197
11231
  } catch (err) {
@@ -11720,9 +11754,6 @@ var plugin = definePlugin({
11720
11754
  return { error: "existingCompanyId is required for preview." };
11721
11755
  }
11722
11756
  const cfg = await ctx.config.get() ?? {};
11723
- const paperclipUrl = cfg.paperclipUrl || process.env.PAPERCLIP_PUBLIC_URL || "http://localhost:3100";
11724
- const paperclipEmail = cfg.paperclipEmail || "";
11725
- const paperclipPassword = cfg.paperclipPassword || "";
11726
11757
  const companyName = typeof params.companyName === "string" && params.companyName.trim() ? params.companyName.trim() : "Preview";
11727
11758
  const templatesDir = await ensureTemplatesDir(cfg);
11728
11759
  tmpDir = path2.join(os.tmpdir(), `company-wizard-preview-update-${Date.now()}`);
@@ -11765,11 +11796,7 @@ var plugin = definePlugin({
11765
11796
  const teamRoles = allRoles.filter((r) => r && r !== "ceo");
11766
11797
  let plannedFiles = 0;
11767
11798
  countFiles2(assembleResult.companyDir);
11768
- const client = new PaperclipClient(paperclipUrl, {
11769
- email: paperclipEmail,
11770
- password: paperclipPassword
11771
- });
11772
- await client.connect();
11799
+ const client = await connectSharedClient(cfg);
11773
11800
  const company = await client.getCompany(existingCompanyId);
11774
11801
  const existingAgents = await client.listAgents(existingCompanyId);
11775
11802
  const existingRoutines = await client.listRoutines(existingCompanyId);
@@ -11902,19 +11929,29 @@ var plugin = definePlugin({
11902
11929
  }
11903
11930
  });
11904
11931
  ctx.actions.register("check-auth", async () => {
11905
- const cfg = await ctx.config.get() ?? {};
11906
- const paperclipUrl = cfg.paperclipUrl || process.env.PAPERCLIP_PUBLIC_URL || "http://localhost:3100";
11907
11932
  try {
11908
- const client = new PaperclipClient(paperclipUrl, {
11909
- email: cfg.paperclipEmail || "",
11910
- password: cfg.paperclipPassword || ""
11911
- });
11912
- await client.connect();
11933
+ const cfg = await ctx.config.get() ?? {};
11934
+ await connectSharedClient(cfg);
11913
11935
  return { ok: true };
11914
11936
  } catch (err) {
11915
11937
  return { ok: false, error: err instanceof Error ? err.message : String(err) };
11916
11938
  }
11917
11939
  });
11940
+ ctx.actions.register("list-companies", async () => {
11941
+ try {
11942
+ const cfg = await ctx.config.get() ?? {};
11943
+ const client = await connectSharedClient(cfg);
11944
+ const companies = await client.listCompanies();
11945
+ const normalized = (Array.isArray(companies) ? companies : []).filter((c) => c && typeof c.id === "string").map((c) => ({
11946
+ id: c.id,
11947
+ name: typeof c.name === "string" ? c.name : "",
11948
+ description: typeof c.description === "string" ? c.description : ""
11949
+ }));
11950
+ return { companies: normalized };
11951
+ } catch (err) {
11952
+ return { error: err instanceof Error ? err.message : String(err) };
11953
+ }
11954
+ });
11918
11955
  ctx.actions.register("ai-chat", async (params) => {
11919
11956
  try {
11920
11957
  if (params.mode === "poll") {
@@ -11980,9 +12017,7 @@ var plugin = definePlugin({
11980
12017
  };
11981
12018
  try {
11982
12019
  const cfg = await ctx.config.get() ?? {};
11983
- const paperclipUrl = cfg.paperclipUrl || process.env.PAPERCLIP_PUBLIC_URL || "http://localhost:3100";
11984
12020
  const paperclipEmail = cfg.paperclipEmail || "";
11985
- const paperclipPassword = cfg.paperclipPassword || "";
11986
12021
  const enableIsolatedWorktrees = await resolveEnableIsolatedWorkspacesFromInstance(cfg, log);
11987
12022
  const enableEnrichedPersonas = true;
11988
12023
  const companyName = typeof params.companyName === "string" ? params.companyName.trim() : "";
@@ -12006,11 +12041,7 @@ var plugin = definePlugin({
12006
12041
  const goals = collectGoals(selectedPreset, allModules, new Set(effectiveModules));
12007
12042
  const presetBootstrapData = collectPresetBootstrapData(selectedPreset);
12008
12043
  log("Connecting to Paperclip API...");
12009
- const client = new PaperclipClient(paperclipUrl, {
12010
- email: paperclipEmail,
12011
- password: paperclipPassword
12012
- });
12013
- await client.connect();
12044
+ const client = await connectSharedClient(cfg);
12014
12045
  log("Connected.");
12015
12046
  const gitIdentity = {
12016
12047
  name: client.boardUserName || null,
@@ -12530,7 +12561,7 @@ var plugin = definePlugin({
12530
12561
  return {
12531
12562
  companyId,
12532
12563
  issuePrefix: company.issuePrefix,
12533
- paperclipUrl,
12564
+ paperclipUrl: client.baseUrl,
12534
12565
  agentIds: { ceo: ceoAgentId, ...teamAgentIds },
12535
12566
  issueIds,
12536
12567
  logs