@openma/cli 0.6.2 → 0.6.3

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.
Files changed (2) hide show
  1. package/dist/index.js +48 -12
  2. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -25642,8 +25642,11 @@ function dirNameFor(sessionId) {
25642
25642
  if (/^[a-f0-9]{1,12}$/i.test(sessionId)) return sessionId.toLowerCase();
25643
25643
  return createHash("sha256").update(sessionId).digest("hex").slice(0, DIR_NAME_LEN);
25644
25644
  }
25645
+ function sessionScratchDirPath(sessionId) {
25646
+ return join5(paths().sessionsDir, dirNameFor(sessionId));
25647
+ }
25645
25648
  async function ensureSessionCwd(sessionId) {
25646
- const cwd = join5(paths().sessionsDir, dirNameFor(sessionId));
25649
+ const cwd = sessionScratchDirPath(sessionId);
25647
25650
  await mkdir6(cwd, { recursive: true });
25648
25651
  return cwd;
25649
25652
  }
@@ -25651,6 +25654,18 @@ function acpProcessCwd(scratchDir, requestedCwd) {
25651
25654
  const requested = requestedCwd?.trim();
25652
25655
  return requested ? requested : scratchDir;
25653
25656
  }
25657
+ function acpSessionReadyOut(params) {
25658
+ const base = {
25659
+ type: "session.ready",
25660
+ session_id: params.session_id,
25661
+ tenant_id: params.tenant_id,
25662
+ acp_session_id: params.acp_session_id
25663
+ };
25664
+ if (params.freshSpawn && params.scratchDir) {
25665
+ return { ...base, bundle_dir: params.scratchDir, fresh: true };
25666
+ }
25667
+ return base;
25668
+ }
25654
25669
  async function writeBundle(cwd, files) {
25655
25670
  for (const f of files) {
25656
25671
  if (f.path.startsWith("/") || f.path.includes("..")) continue;
@@ -25781,6 +25796,8 @@ var init_session_manager = __esm({
25781
25796
  * doesn't hit "session not ready" mid-stream just because the daemon
25782
25797
  * is on its way out. */
25783
25798
  #draining = false;
25799
+ /** Sessions awaiting their first session.ready on the managed runtime path. */
25800
+ #freshSpawnPending = /* @__PURE__ */ new Set();
25784
25801
  constructor(send, runtimeDependencies) {
25785
25802
  this.#send = send;
25786
25803
  if (runtimeDependencies) {
@@ -25813,11 +25830,25 @@ var init_session_manager = __esm({
25813
25830
  }
25814
25831
  #publishManagedRuntimeEvent(event) {
25815
25832
  const scope = this.#runtimeScopes.get(event.sessionId);
25816
- this.#send(encodeSessionHostEvent(event, {
25817
- tenantId: scope?.id
25818
- }));
25833
+ if (event.type === "session.ready" && this.#freshSpawnPending.delete(event.sessionId)) {
25834
+ this.#send(acpSessionReadyOut({
25835
+ session_id: event.sessionId,
25836
+ tenant_id: scope?.id ?? "",
25837
+ acp_session_id: event.acpSessionId,
25838
+ scratchDir: sessionScratchDirPath(event.sessionId),
25839
+ freshSpawn: true
25840
+ }));
25841
+ } else {
25842
+ this.#send(encodeSessionHostEvent(event, {
25843
+ tenantId: scope?.id
25844
+ }));
25845
+ }
25819
25846
  if (event.type === "session.disposed") {
25820
25847
  this.#runtimeScopes.delete(event.sessionId);
25848
+ this.#freshSpawnPending.delete(event.sessionId);
25849
+ }
25850
+ if (event.type === "session.error") {
25851
+ this.#freshSpawnPending.delete(event.sessionId);
25821
25852
  }
25822
25853
  }
25823
25854
  setSpawnEnv(env) {
@@ -25867,7 +25898,11 @@ var init_session_manager = __esm({
25867
25898
  return;
25868
25899
  }
25869
25900
  for (const [session_id, sess] of this.#sessions) {
25870
- this.#send({ type: "session.ready", session_id, tenant_id: sess.tenantId, acp_session_id: sess.acpSessionId });
25901
+ this.#send(acpSessionReadyOut({
25902
+ session_id,
25903
+ tenant_id: sess.tenantId,
25904
+ acp_session_id: sess.acpSessionId
25905
+ }));
25871
25906
  }
25872
25907
  }
25873
25908
  async start(p) {
@@ -25912,6 +25947,7 @@ var init_session_manager = __esm({
25912
25947
  id: tenantId,
25913
25948
  agentApiKey: tenantKey
25914
25949
  });
25950
+ this.#freshSpawnPending.add(p.session_id);
25915
25951
  }
25916
25952
  await this.#managedRuntime.dispatch({
25917
25953
  type: "session.start",
@@ -25925,12 +25961,11 @@ var init_session_manager = __esm({
25925
25961
  }
25926
25962
  const existing = this.#sessions.get(p.session_id);
25927
25963
  if (existing) {
25928
- this.#send({
25929
- type: "session.ready",
25964
+ this.#send(acpSessionReadyOut({
25930
25965
  session_id: p.session_id,
25931
25966
  tenant_id: existing.tenantId,
25932
25967
  acp_session_id: existing.acpSessionId
25933
- });
25968
+ }));
25934
25969
  return;
25935
25970
  }
25936
25971
  const agent = resolveKnownAgent(p.agent_id);
@@ -26021,12 +26056,13 @@ var init_session_manager = __esm({
26021
26056
  tenantId,
26022
26057
  turns: /* @__PURE__ */ new Map()
26023
26058
  });
26024
- this.#send({
26025
- type: "session.ready",
26059
+ this.#send(acpSessionReadyOut({
26026
26060
  session_id: p.session_id,
26027
26061
  tenant_id: tenantId,
26028
- acp_session_id: session.acpSessionId
26029
- });
26062
+ acp_session_id: session.acpSessionId,
26063
+ scratchDir,
26064
+ freshSpawn: true
26065
+ }));
26030
26066
  } catch (e) {
26031
26067
  this.#send({
26032
26068
  type: "session.error",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openma/cli",
3
- "version": "0.6.2",
3
+ "version": "0.6.3",
4
4
  "description": "CLI for the openma managed agents platform",
5
5
  "type": "module",
6
6
  "bin": {
@@ -44,9 +44,9 @@
44
44
  "typescript": "^7.0.2",
45
45
  "vitest": "^4.1.3",
46
46
  "ws": "^8.18.0",
47
- "@open-managed-agents/acp-runtime": "0.0.0",
48
47
  "@open-managed-agents/api-types": "0.1.0",
49
- "@open-managed-agents/runtime": "0.1.0"
48
+ "@open-managed-agents/runtime": "0.1.0",
49
+ "@open-managed-agents/acp-runtime": "0.0.0"
50
50
  },
51
51
  "scripts": {
52
52
  "build": "esbuild src/index.ts --bundle --platform=node --format=esm --outfile=dist/index.js --banner:js=\"#!/usr/bin/env node\nimport { createRequire as __cr } from 'node:module'; const require = __cr(import.meta.url);\"",