@agimon-ai/po-author 0.0.0-alpha.56 → 0.0.0-alpha.58

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.
@@ -10,6 +10,7 @@ let node_crypto = require("node:crypto");
10
10
  let node_path = require("node:path");
11
11
  node_path = require_structuredDocuments.__toESM(node_path, 1);
12
12
  let _agimon_ai_po_core_extensionFile = require("@agimon-ai/po-core/extensionFile");
13
+ let _agimon_ai_po_artifact = require("@agimon-ai/po-artifact");
13
14
  let _agimon_ai_po_core_codemode = require("@agimon-ai/po-core/codemode");
14
15
  let hono = require("hono");
15
16
  let node_fs = require("node:fs");
@@ -150,10 +151,10 @@ async function resolveDocument(cwd, requestedPath, sessionId, environment) {
150
151
  realPath: realCandidate
151
152
  };
152
153
  }
153
- async function readArtifact(root, relative) {
154
+ async function readArtifact(root, relative, workflowVisible) {
154
155
  let file;
155
156
  try {
156
- file = await (0, _agimon_ai_po_artifact_artifactFiles.openArtifact)(root, relative);
157
+ file = await (0, _agimon_ai_po_artifact_artifactFiles.openArtifact)(root, relative, workflowVisible);
157
158
  } catch (error) {
158
159
  if (error instanceof _agimon_ai_po_artifact_artifactFiles.ArtifactAccessError) throw new require_structuredDocuments.DocumentRequestError(error.message, error.status);
159
160
  throw error;
@@ -165,8 +166,8 @@ async function readArtifact(root, relative) {
165
166
  await file.handle.close();
166
167
  }
167
168
  }
168
- async function readSource(source) {
169
- if (source.kind === "artifact") return await readArtifact(source.root, source.relative);
169
+ async function readSource(source, workflowVisible) {
170
+ if (source.kind === "artifact") return await readArtifact(source.root, source.relative, workflowVisible);
170
171
  if (process.platform !== "darwin" && process.platform !== "linux") throw new require_structuredDocuments.DocumentRequestError("Secure document reads require macOS or Linux.", 403);
171
172
  const noFollow = process.platform === "darwin" ? 536870912 : node_fs.constants.O_NOFOLLOW;
172
173
  const handle = await node_fs_promises.default.open(source.realPath, node_fs.constants.O_RDONLY | node_fs.constants.O_NONBLOCK | noFollow);
@@ -181,12 +182,12 @@ async function readSource(source) {
181
182
  await handle.close();
182
183
  }
183
184
  }
184
- async function readDocument(cwd, requestedPath, sessionId, environment) {
185
- return await readSource(await resolveDocument(cwd, requestedPath, sessionId, environment));
185
+ async function readDocument(cwd, requestedPath, sessionId, environment, workflowVisible) {
186
+ return await readSource(await resolveDocument(cwd, requestedPath, sessionId, environment), workflowVisible);
186
187
  }
187
188
  //#endregion
188
189
  //#region src/services/authorCanvasRegistry/index.ts
189
- function createAuthorCanvasRegistry(cwd, createBridge, sessionId, environment) {
190
+ function createAuthorCanvasRegistry(cwd, createBridge, sessionId, environment, workflowVisible) {
190
191
  const byAlias = /* @__PURE__ */ new Map();
191
192
  const byPath = /* @__PURE__ */ new Map();
192
193
  const retired = /* @__PURE__ */ new Map();
@@ -234,7 +235,7 @@ function createAuthorCanvasRegistry(cwd, createBridge, sessionId, environment) {
234
235
  signal?.throwIfAborted();
235
236
  if (requestedAlias !== void 0 && !require_structuredDocuments.AUTHOR_ALIAS_PATTERN.test(requestedAlias)) throw new require_structuredDocuments.AuthorBridgeError("Invalid Author canvas alias.", 400);
236
237
  const source = await resolveDocument(cwd, requestedPath, sessionId, environment);
237
- const bytes = await readSource(source);
238
+ const bytes = await readSource(source, workflowVisible);
238
239
  signal?.throwIfAborted();
239
240
  const { realPath, path: canonicalPath } = source;
240
241
  const occupied = requestedAlias === void 0 ? void 0 : byAlias.get(requestedAlias);
@@ -581,7 +582,7 @@ function createAuthorDocumentApi(options = {}) {
581
582
  app.get(apiRoutes_default.file.path, async (context) => {
582
583
  try {
583
584
  const source = await resolveDocument(admittedCwd(), context.req.query("path"), options.sessionId, options.environment);
584
- const bytes = await readSource(source);
585
+ const bytes = await readSource(source, options.workflowVisible);
585
586
  return new Response(bytes, { headers: {
586
587
  "Content-Type": (0, hono_utils_mime.getMimeType)(source.path) ?? "application/octet-stream",
587
588
  "Content-Length": String(bytes.byteLength),
@@ -642,7 +643,7 @@ function createAuthorDocumentApi(options = {}) {
642
643
  try {
643
644
  const body = await bodyOf(context.req.raw);
644
645
  if (body.format === void 0 && options.open !== void 0) return context.json(await options.open(body.path, context.req.raw.signal, body.alias));
645
- const bytes = await readDocument(admittedCwd(), body.path, options.sessionId, options.environment);
646
+ const bytes = await readDocument(admittedCwd(), body.path, options.sessionId, options.environment, options.workflowVisible);
646
647
  if (body.format === void 0) return context.json({
647
648
  path: body.path,
648
649
  byteLength: bytes.byteLength
@@ -655,7 +656,7 @@ function createAuthorDocumentApi(options = {}) {
655
656
  app.post(apiRoutes_default.documentsPreflight.path, async (context) => {
656
657
  try {
657
658
  const body = await bodyOf(context.req.raw);
658
- const bytes = await readDocument(admittedCwd(), body.path, options.sessionId, options.environment);
659
+ const bytes = await readDocument(admittedCwd(), body.path, options.sessionId, options.environment, options.workflowVisible);
659
660
  return context.json(await require_structuredDocuments.preflightStructuredDocument(requestFormat(body.format), bytes, requestOperations(body.operations), body.csvDialect));
660
661
  } catch (error) {
661
662
  return errorResponse(context, error);
@@ -665,7 +666,7 @@ function createAuthorDocumentApi(options = {}) {
665
666
  try {
666
667
  const body = await bodyOf(context.req.raw);
667
668
  if (typeof body.preflightDigest !== "string") throw new Error("A preflight report digest is required.");
668
- const bytes = await readDocument(admittedCwd(), body.path, options.sessionId, options.environment);
669
+ const bytes = await readDocument(admittedCwd(), body.path, options.sessionId, options.environment, options.workflowVisible);
669
670
  const serialized = await require_structuredDocuments.serializeStructuredDocument(requestFormat(body.format), bytes, requestOperations(body.operations), body.preflightDigest, body.csvDialect);
670
671
  return context.json({
671
672
  bytes: Buffer.from(serialized.bytes).toString("base64"),
@@ -697,7 +698,7 @@ const createBridge = () => require_structuredDocuments.createAuthorBridgeState({
697
698
  function createAuthorApi(options = {}) {
698
699
  if (options.cwd === void 0) throw new Error("Author requires the session working directory.");
699
700
  const app = new hono.Hono();
700
- const registry = options.registry ?? createAuthorCanvasRegistry(options.cwd, createBridge, options.sessionId, options.environment);
701
+ const registry = options.registry ?? createAuthorCanvasRegistry(options.cwd, createBridge, options.sessionId, options.environment, options.workflowVisible);
701
702
  app.get(apiRoutes_default.state.path, (context) => context.json({
702
703
  sessionId: options.sessionId ?? null,
703
704
  ...(options.readState ?? inactiveState)()
@@ -707,6 +708,7 @@ function createAuthorApi(options = {}) {
707
708
  ...options.cwd === void 0 ? {} : { cwd: options.cwd },
708
709
  ...options.sessionId === void 0 ? {} : { sessionId: options.sessionId },
709
710
  ...options.environment === void 0 ? {} : { environment: options.environment },
711
+ workflowVisible: options.workflowVisible,
710
712
  open: (path, signal, alias) => registry.open(path, signal, alias)
711
713
  }));
712
714
  return app;
@@ -729,8 +731,8 @@ const api = {
729
731
  }
730
732
  };
731
733
  /** The session API and tools share the same browser ownership and pending requests. */
732
- function createAuthorSessionApi(cwd, sessionId, environment, publishCanvases) {
733
- const registry = createAuthorCanvasRegistry(cwd, createBridge, sessionId, environment);
734
+ function createAuthorSessionApi(cwd, sessionId, environment, publishCanvases, workflowVisible) {
735
+ const registry = createAuthorCanvasRegistry(cwd, createBridge, sessionId, environment, workflowVisible);
734
736
  if (publishCanvases !== void 0) {
735
737
  registry.onChange(() => publishCanvases(registry.openCanvases()));
736
738
  publishCanvases([]);
@@ -751,7 +753,8 @@ function createAuthorSessionApi(cwd, sessionId, environment, publishCanvases) {
751
753
  cwd,
752
754
  sessionId,
753
755
  environment,
754
- registry
756
+ registry,
757
+ workflowVisible
755
758
  });
756
759
  return {
757
760
  fetch: (request) => app.fetch(request),
@@ -763,10 +766,13 @@ function createAuthorSessionApi(cwd, sessionId, environment, publishCanvases) {
763
766
  }
764
767
  //#endregion
765
768
  //#region src/extensions/workspaces/sessions/(backend)/root.server.ts
766
- var root_server_default = (0, _agimon_ai_po_core_extensionFile.defineRoot)(({ agent, host, signal }) => {
769
+ var root_server_default = (0, _agimon_ai_po_core_extensionFile.defineRoot)(({ agent, host, context, signal }) => {
767
770
  const { environment, directEvents } = host.context;
768
771
  if (agent && environment === void 0) throw new Error("Author requires an admitted session environment.");
769
- const session = agent && environment ? createAuthorSessionApi(agent.context.cwd, agent.context.sessionId, environment, (canvases) => directEvents?.publish(authorCanvasesFrame, agent.context.sessionId, { canvases })) : void 0;
772
+ const workflowVisible = (relativePath, kind) => !signal.aborted && context.get(_agimon_ai_po_artifact.ARTIFACTS_SERVICE)?.workflowVisible(relativePath, kind) === true;
773
+ const cwd = agent?.context.cwd ?? host.context.cwd;
774
+ const sessionId = agent?.context.sessionId ?? host.context.sessionId;
775
+ const session = cwd && sessionId && environment ? createAuthorSessionApi(cwd, sessionId, environment, (canvases) => directEvents?.publish(authorCanvasesFrame, sessionId, { canvases }), workflowVisible) : void 0;
770
776
  const isActive = () => (agent?.context.selection.state?.["minor-mode"] ?? []).includes(require_structuredDocuments.authorMinorMode.descriptor.id);
771
777
  const mode = agent ? require_structuredDocuments.authorMinorMode.createOwner({
772
778
  isActive,