@librechat/agents 3.1.90 → 3.1.92

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 (94) hide show
  1. package/dist/cjs/agents/AgentContext.cjs +9 -5
  2. package/dist/cjs/agents/AgentContext.cjs.map +1 -1
  3. package/dist/cjs/graphs/Graph.cjs +48 -14
  4. package/dist/cjs/graphs/Graph.cjs.map +1 -1
  5. package/dist/cjs/instrumentation.cjs +2 -7
  6. package/dist/cjs/instrumentation.cjs.map +1 -1
  7. package/dist/cjs/langfuse.cjs +285 -0
  8. package/dist/cjs/langfuse.cjs.map +1 -0
  9. package/dist/cjs/main.cjs +25 -0
  10. package/dist/cjs/main.cjs.map +1 -1
  11. package/dist/cjs/run.cjs +75 -44
  12. package/dist/cjs/run.cjs.map +1 -1
  13. package/dist/cjs/stream.cjs +10 -3
  14. package/dist/cjs/stream.cjs.map +1 -1
  15. package/dist/cjs/tools/cloudflare/CloudflareBridgeRuntime.cjs +380 -0
  16. package/dist/cjs/tools/cloudflare/CloudflareBridgeRuntime.cjs.map +1 -0
  17. package/dist/cjs/tools/cloudflare/CloudflareProgrammaticToolCalling.cjs +997 -0
  18. package/dist/cjs/tools/cloudflare/CloudflareProgrammaticToolCalling.cjs.map +1 -0
  19. package/dist/cjs/tools/cloudflare/CloudflareSandboxExecutionEngine.cjs +575 -0
  20. package/dist/cjs/tools/cloudflare/CloudflareSandboxExecutionEngine.cjs.map +1 -0
  21. package/dist/cjs/tools/cloudflare/CloudflareSandboxTools.cjs +165 -0
  22. package/dist/cjs/tools/cloudflare/CloudflareSandboxTools.cjs.map +1 -0
  23. package/dist/cjs/tools/local/LocalExecutionEngine.cjs +17 -5
  24. package/dist/cjs/tools/local/LocalExecutionEngine.cjs.map +1 -1
  25. package/dist/cjs/tools/local/resolveLocalExecutionTools.cjs +110 -6
  26. package/dist/cjs/tools/local/resolveLocalExecutionTools.cjs.map +1 -1
  27. package/dist/cjs/utils/callbacks.cjs +27 -0
  28. package/dist/cjs/utils/callbacks.cjs.map +1 -0
  29. package/dist/esm/agents/AgentContext.mjs +9 -5
  30. package/dist/esm/agents/AgentContext.mjs.map +1 -1
  31. package/dist/esm/graphs/Graph.mjs +48 -14
  32. package/dist/esm/graphs/Graph.mjs.map +1 -1
  33. package/dist/esm/instrumentation.mjs +2 -7
  34. package/dist/esm/instrumentation.mjs.map +1 -1
  35. package/dist/esm/langfuse.mjs +275 -0
  36. package/dist/esm/langfuse.mjs.map +1 -0
  37. package/dist/esm/main.mjs +5 -1
  38. package/dist/esm/main.mjs.map +1 -1
  39. package/dist/esm/run.mjs +75 -44
  40. package/dist/esm/run.mjs.map +1 -1
  41. package/dist/esm/stream.mjs +10 -3
  42. package/dist/esm/stream.mjs.map +1 -1
  43. package/dist/esm/tools/cloudflare/CloudflareBridgeRuntime.mjs +378 -0
  44. package/dist/esm/tools/cloudflare/CloudflareBridgeRuntime.mjs.map +1 -0
  45. package/dist/esm/tools/cloudflare/CloudflareProgrammaticToolCalling.mjs +994 -0
  46. package/dist/esm/tools/cloudflare/CloudflareProgrammaticToolCalling.mjs.map +1 -0
  47. package/dist/esm/tools/cloudflare/CloudflareSandboxExecutionEngine.mjs +566 -0
  48. package/dist/esm/tools/cloudflare/CloudflareSandboxExecutionEngine.mjs.map +1 -0
  49. package/dist/esm/tools/cloudflare/CloudflareSandboxTools.mjs +155 -0
  50. package/dist/esm/tools/cloudflare/CloudflareSandboxTools.mjs.map +1 -0
  51. package/dist/esm/tools/local/LocalExecutionEngine.mjs +17 -6
  52. package/dist/esm/tools/local/LocalExecutionEngine.mjs.map +1 -1
  53. package/dist/esm/tools/local/resolveLocalExecutionTools.mjs +111 -7
  54. package/dist/esm/tools/local/resolveLocalExecutionTools.mjs.map +1 -1
  55. package/dist/esm/utils/callbacks.mjs +24 -0
  56. package/dist/esm/utils/callbacks.mjs.map +1 -0
  57. package/dist/types/agents/AgentContext.d.ts +4 -1
  58. package/dist/types/graphs/Graph.d.ts +6 -5
  59. package/dist/types/index.d.ts +1 -0
  60. package/dist/types/langfuse.d.ts +57 -0
  61. package/dist/types/tools/cloudflare/CloudflareBridgeRuntime.d.ts +23 -0
  62. package/dist/types/tools/cloudflare/CloudflareProgrammaticToolCalling.d.ts +4 -0
  63. package/dist/types/tools/cloudflare/CloudflareSandboxExecutionEngine.d.ts +21 -0
  64. package/dist/types/tools/cloudflare/CloudflareSandboxTools.d.ts +22 -0
  65. package/dist/types/tools/cloudflare/index.d.ts +4 -0
  66. package/dist/types/tools/local/LocalExecutionEngine.d.ts +1 -0
  67. package/dist/types/types/graph.d.ts +8 -0
  68. package/dist/types/types/run.d.ts +2 -2
  69. package/dist/types/types/tools.d.ts +118 -2
  70. package/dist/types/utils/callbacks.d.ts +5 -0
  71. package/package.json +4 -4
  72. package/src/__tests__/stream.eagerEventExecution.test.ts +66 -0
  73. package/src/agents/AgentContext.ts +13 -3
  74. package/src/graphs/Graph.ts +57 -16
  75. package/src/index.ts +1 -0
  76. package/src/instrumentation.ts +2 -7
  77. package/src/langfuse.ts +441 -0
  78. package/src/run.ts +105 -59
  79. package/src/specs/langfuse-callbacks.test.ts +75 -0
  80. package/src/specs/langfuse-config.test.ts +114 -0
  81. package/src/specs/langfuse-metadata.test.ts +19 -1
  82. package/src/stream.ts +13 -3
  83. package/src/tools/__tests__/CloudflareSandboxExecution.test.ts +537 -0
  84. package/src/tools/cloudflare/CloudflareBridgeRuntime.ts +480 -0
  85. package/src/tools/cloudflare/CloudflareProgrammaticToolCalling.ts +1162 -0
  86. package/src/tools/cloudflare/CloudflareSandboxExecutionEngine.ts +744 -0
  87. package/src/tools/cloudflare/CloudflareSandboxTools.ts +225 -0
  88. package/src/tools/cloudflare/index.ts +4 -0
  89. package/src/tools/local/LocalExecutionEngine.ts +20 -4
  90. package/src/tools/local/resolveLocalExecutionTools.ts +169 -7
  91. package/src/types/graph.ts +9 -0
  92. package/src/types/run.ts +2 -7
  93. package/src/types/tools.ts +141 -2
  94. package/src/utils/callbacks.ts +39 -0
@@ -505,11 +505,12 @@ export type ToolOutputReferencesConfig = {
505
505
  maxTotalSize?: number;
506
506
  };
507
507
 
508
- export type ToolExecutionEngine = 'sandbox' | 'local';
508
+ export type ToolExecutionEngine = 'sandbox' | 'local' | 'cloudflare-sandbox';
509
509
 
510
510
  /**
511
511
  * Records pre-write file contents so callers can rewind edits/writes
512
- * made by the local engine. Implementations live in `src/tools/local`.
512
+ * made by local-compatible coding-tool engines. Implementations live
513
+ * in `src/tools/local`.
513
514
  */
514
515
  export interface LocalFileCheckpointer {
515
516
  /**
@@ -634,6 +635,12 @@ export type LocalExecConfig = {
634
635
  * overridden together for non-host engines.
635
636
  */
636
637
  fs?: import('@/tools/local/workspaceFS').WorkspaceFS;
638
+ /**
639
+ * Set by custom execution backends that already provide their own
640
+ * sandbox boundary. Suppresses the local host-sandbox warning while
641
+ * preserving the warning for plain host `child_process` execution.
642
+ */
643
+ sandboxed?: boolean;
637
644
  };
638
645
 
639
646
  export type LocalExecutionConfig = {
@@ -790,11 +797,143 @@ export type LocalExecutionConfig = {
790
797
  };
791
798
  };
792
799
 
800
+ export type CloudflareSandboxExecOptions = {
801
+ cwd?: string;
802
+ env?: Record<string, string | undefined>;
803
+ timeout?: number;
804
+ stream?: boolean;
805
+ onOutput?: (stream: 'stdout' | 'stderr', data: string) => void;
806
+ signal?: AbortSignal;
807
+ };
808
+
809
+ export type CloudflareSandboxExecResult = {
810
+ success?: boolean;
811
+ exitCode: number;
812
+ stdout: string;
813
+ stderr: string;
814
+ command?: string;
815
+ duration?: number;
816
+ timestamp?: string;
817
+ };
818
+
819
+ export type CloudflareSandboxReadFileResult =
820
+ | string
821
+ | Buffer
822
+ | Uint8Array
823
+ | {
824
+ content: string | Buffer | Uint8Array | ReadableStream<Uint8Array>;
825
+ size?: number;
826
+ mimeType?: string;
827
+ encoding?: 'utf-8' | 'utf8' | 'base64';
828
+ isBinary?: boolean;
829
+ };
830
+
831
+ export type CloudflareSandboxListFilesOptions = {
832
+ recursive?: boolean;
833
+ includeHidden?: boolean;
834
+ };
835
+
836
+ export type CloudflareSandboxFileInfo = {
837
+ name: string;
838
+ absolutePath?: string;
839
+ relativePath?: string;
840
+ type?: 'file' | 'directory' | 'symlink' | 'other';
841
+ size?: number;
842
+ modifiedAt?: string;
843
+ mode?: string;
844
+ };
845
+
846
+ export type CloudflareSandboxListFilesResult =
847
+ | CloudflareSandboxFileInfo[]
848
+ | {
849
+ files: CloudflareSandboxFileInfo[];
850
+ count?: number;
851
+ path?: string;
852
+ success?: boolean;
853
+ };
854
+
855
+ export interface CloudflareSandboxRuntime {
856
+ exec(
857
+ command: string,
858
+ options?: CloudflareSandboxExecOptions
859
+ ): Promise<CloudflareSandboxExecResult>;
860
+ readFile(
861
+ path: string,
862
+ options?: { encoding?: string }
863
+ ): Promise<CloudflareSandboxReadFileResult>;
864
+ writeFile(
865
+ path: string,
866
+ content: string | ReadableStream<Uint8Array>,
867
+ options?: { encoding?: string }
868
+ ): Promise<unknown>;
869
+ mkdir(path: string, options?: { recursive?: boolean }): Promise<unknown>;
870
+ listFiles(
871
+ path: string,
872
+ options?: CloudflareSandboxListFilesOptions
873
+ ): Promise<CloudflareSandboxListFilesResult>;
874
+ deleteFile(path: string): Promise<unknown>;
875
+ }
876
+
877
+ export type CloudflareSandboxExecutionConfig = {
878
+ sandbox:
879
+ | CloudflareSandboxRuntime
880
+ | (() => CloudflareSandboxRuntime | Promise<CloudflareSandboxRuntime>);
881
+ /** Working directory inside the sandbox. Defaults to `/workspace`. */
882
+ workspaceRoot?: string;
883
+ /** Extra environment variables merged into sandbox command executions. */
884
+ env?: Record<string, string | undefined>;
885
+ /** Default timeout for sandbox commands, in milliseconds. */
886
+ timeoutMs?: number;
887
+ /** Maximum stdout/stderr characters surfaced to the model. */
888
+ maxOutputChars?: number;
889
+ /**
890
+ * Add the built-in coding suite when `engine` is `cloudflare-sandbox`.
891
+ * Defaults to true, matching the local execution backend.
892
+ */
893
+ includeCodingTools?: boolean;
894
+ /**
895
+ * Optional exact coding-tool names to expose when `includeCodingTools`
896
+ * is on. Defaults to the full local-parity Cloudflare bundle. Use this
897
+ * to publish a bash-only sandbox surface, for example file/search tools
898
+ * plus `bash_tool` and `run_tools_with_bash`, without exposing
899
+ * `execute_code`.
900
+ */
901
+ codingToolNames?: readonly string[];
902
+ /** Optional shell executable for bash-style tools. Defaults to `bash`. */
903
+ shell?: string;
904
+ /**
905
+ * Optional project-level compile check configuration. Mirrors the local
906
+ * execution backend.
907
+ */
908
+ compileCheck?: LocalExecutionConfig['compileCheck'];
909
+ /** Optional read-only guard for mutating coding tools. */
910
+ readOnly?: boolean;
911
+ /** Permit dangerous commands that the validator otherwise blocks. */
912
+ allowDangerousCommands?: LocalExecutionConfig['allowDangerousCommands'];
913
+ /** Tree-sitter-bash AST validation pass for bash commands. */
914
+ bashAst?: LocalExecutionConfig['bashAst'];
915
+ /**
916
+ * Enable per-Run file checkpointing for `edit_file` / `write_file`
917
+ * against the Cloudflare Sandbox workspace.
918
+ */
919
+ fileCheckpointing?: LocalExecutionConfig['fileCheckpointing'];
920
+ /** Maximum bytes to read in `read_file` before returning a stub. */
921
+ maxReadBytes?: LocalExecutionConfig['maxReadBytes'];
922
+ /** Controls whether `read_file` returns binary files as attachments. */
923
+ attachReadAttachments?: LocalExecutionConfig['attachReadAttachments'];
924
+ /** Maximum pre-encoding byte size to embed inline. */
925
+ maxAttachmentBytes?: LocalExecutionConfig['maxAttachmentBytes'];
926
+ /** Run a fast per-file syntax check after successful edits/writes. */
927
+ postEditSyntaxCheck?: LocalExecutionConfig['postEditSyntaxCheck'];
928
+ };
929
+
793
930
  export type ToolExecutionConfig = {
794
931
  /** `sandbox` preserves the remote Code API behavior and is the default. */
795
932
  engine?: ToolExecutionEngine;
796
933
  /** Local process execution settings used when `engine` is `local`. */
797
934
  local?: LocalExecutionConfig;
935
+ /** Cloudflare Sandbox execution settings used when `engine` is `cloudflare-sandbox`. */
936
+ cloudflare?: CloudflareSandboxExecutionConfig;
798
937
  };
799
938
 
800
939
  export type ProgrammaticCache = {
@@ -0,0 +1,39 @@
1
+ import { ensureHandler } from '@langchain/core/callbacks/manager';
2
+ import type {
3
+ BaseCallbackHandler,
4
+ CallbackHandlerMethods,
5
+ } from '@langchain/core/callbacks/base';
6
+ import type { Callbacks } from '@langchain/core/callbacks/manager';
7
+
8
+ export type CallbackEntry = BaseCallbackHandler | CallbackHandlerMethods;
9
+
10
+ export function appendCallbacks(
11
+ callbacks: Callbacks | undefined,
12
+ additions: readonly CallbackEntry[]
13
+ ): Callbacks {
14
+ if (additions.length === 0) {
15
+ return callbacks ?? [];
16
+ }
17
+
18
+ if (callbacks == null) {
19
+ return [...additions];
20
+ }
21
+
22
+ if (Array.isArray(callbacks)) {
23
+ return callbacks.concat(additions);
24
+ }
25
+
26
+ return callbacks.copy(additions.map(ensureHandler));
27
+ }
28
+
29
+ export function findCallback(
30
+ callbacks: Callbacks | undefined,
31
+ predicate: (callback: CallbackEntry) => boolean
32
+ ): CallbackEntry | undefined {
33
+ if (callbacks == null) {
34
+ return undefined;
35
+ }
36
+
37
+ const handlers = Array.isArray(callbacks) ? callbacks : callbacks.handlers;
38
+ return handlers.find(predicate);
39
+ }