@myagentroam/agent 0.15.27 → 0.15.28

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.
@@ -1,3 +1,4 @@
1
+ import { addAbortListener } from 'node:events';
1
2
  import { RuntimeResourceHandles } from '../tools/runtime-resource-handles.js';
2
3
  import { StringDecoder } from 'node:string_decoder';
3
4
  import { AgentError } from '../error.js';
@@ -82,7 +83,7 @@ export class ExecTool {
82
83
  if (input.action === 'write') {
83
84
  if (process.status !== 'running')
84
85
  throw new AgentError('MAR_AGENT_TOOL_INPUT_INVALID', 'Completed process cannot accept input.');
85
- process.child.stdin.write(input.data);
86
+ await writeProcessInput(process.child.stdin, input.data, signal);
86
87
  }
87
88
  if (input.action === 'cancel') {
88
89
  // Mark before awaiting termination so concurrent collection cannot evict another replay.
@@ -201,6 +202,8 @@ export class ExecTool {
201
202
  });
202
203
  }
203
204
  if (!native) {
205
+ // The write callback reports the call failure, but Node also emits a separate error event.
206
+ child.stdin.on('error', () => { });
204
207
  const listen = (name) => child[name].on('data', (chunk) => {
205
208
  if (managed.finalized)
206
209
  return;
@@ -762,6 +765,32 @@ function watchProcessOutput(processId, managed, onOutput) {
762
765
  schedule();
763
766
  return subscription.stop;
764
767
  }
768
+ async function writeProcessInput(stdin, data, signal) {
769
+ const failure = (reasonCode) => new AgentError('MAR_AGENT_PROCESS_IO_FAILED', 'Managed process input failed.', {
770
+ details: { reasonCode }
771
+ });
772
+ if (signal?.aborted)
773
+ throw executionAbortReason(signal);
774
+ if (!stdin.writable)
775
+ throw failure('STDIN_CLOSED');
776
+ let listener;
777
+ try {
778
+ await new Promise((resolve, reject) => {
779
+ // Cancel only the wait; bytes already submitted to the pipe cannot be withdrawn.
780
+ if (signal)
781
+ listener = addAbortListener(signal, () => reject(executionAbortReason(signal)));
782
+ try {
783
+ stdin.write(data, (error) => error ? reject(failure(error.code ?? 'UNKNOWN')) : resolve());
784
+ }
785
+ catch (error) {
786
+ reject(failure(error?.code ?? 'UNKNOWN'));
787
+ }
788
+ });
789
+ }
790
+ finally {
791
+ listener?.[Symbol.dispose]();
792
+ }
793
+ }
765
794
  function executionAbortReason(signal) {
766
795
  return signal?.reason ?? new AgentError('MAR_AGENT_EXECUTION_CANCELLED', 'Execution cancelled.');
767
796
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@myagentroam/agent",
3
- "version": "0.15.27",
3
+ "version": "0.15.28",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/myagentroam/mar.git",