@mondaydotcomorg/atp-server 0.20.1 → 0.20.2

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/index.js CHANGED
@@ -2,7 +2,7 @@ import { log, isReplayMode, setCurrentExecutionId, getAPIResultFromCache, approv
2
2
  import fs, { readFile } from 'fs/promises';
3
3
  import yaml from 'js-yaml';
4
4
  import { createServer as createServer$1 } from 'http';
5
- import { ProvenanceMode, ToolOperationType, ToolSensitivityLevel, CallbackType, ToolOperation, ExecutionStatus, sanitizeInput, MAX_CODE_SIZE, ExecutionErrorCode } from '@mondaydotcomorg/atp-protocol';
5
+ import { ProvenanceMode, ToolOperationType, ToolSensitivityLevel, createToolStartEvent, createToolEndEvent, CallbackType, ToolOperation, ExecutionStatus, sanitizeInput, MAX_CODE_SIZE, ExecutionErrorCode } from '@mondaydotcomorg/atp-protocol';
6
6
  import { getProvenance, createProvenanceProxy, ProvenanceSource, setProvenanceExecutionId, SecurityPolicyEngine, createTrackingRuntime, registerProvenanceMetadata, instrumentCode, captureProvenanceSnapshot, cleanupProvenanceForExecution, clearProvenanceExecutionId, DynamicPolicyRegistry, getProvenanceForPrimitive, computeDigest, verifyProvenanceHints, restoreProvenanceSnapshot, markPrimitiveTainted, ProvenanceMode as ProvenanceMode$1, issueProvenanceToken } from '@mondaydotcomorg/atp-provenance';
7
7
  export { ProvenanceMode, ProvenanceSecurityError, ProvenanceSource, SecurityPolicyEngine, auditSensitiveAccess, blockLLMRecipients, blockLLMRecipientsWithApproval, canRead, captureProvenanceState, cleanupProvenanceForExecution, clearProvenanceExecutionId, createCustomPolicy, createProvenanceProxy, createTrackingRuntime, getAllProvenance, getBuiltInPolicies, getBuiltInPoliciesWithApproval, getProvenance, getProvenanceForPrimitive, hasProvenance, instrumentCode, isPrimitiveTainted, markPrimitiveTainted, preventDataExfiltration, preventDataExfiltrationWithApproval, requireUserOrigin, requireUserOriginWithApproval, restoreProvenanceState, setProvenanceExecutionId } from '@mondaydotcomorg/atp-provenance';
8
8
  import crypto, { randomBytes, randomUUID } from 'crypto';
@@ -7068,6 +7068,24 @@ function reattachProvenanceFromHints(args, hintMap) {
7068
7068
  __name(reattachProvenanceFromHints, "reattachProvenanceFromHints");
7069
7069
 
7070
7070
  // src/executor/sandbox-builder.ts
7071
+ function createEventEmitter(eventCallback) {
7072
+ return (eventOrType, data, runId) => {
7073
+ if (!eventCallback) return;
7074
+ const event = typeof eventOrType === "string" ? {
7075
+ type: eventOrType,
7076
+ data,
7077
+ timestamp: Date.now(),
7078
+ runId
7079
+ } : eventOrType;
7080
+ setImmediate(() => {
7081
+ try {
7082
+ eventCallback(event);
7083
+ } catch (error) {
7084
+ }
7085
+ });
7086
+ };
7087
+ }
7088
+ __name(createEventEmitter, "createEventEmitter");
7071
7089
  var SandboxBuilder = class {
7072
7090
  static {
7073
7091
  __name(this, "SandboxBuilder");
@@ -7426,21 +7444,25 @@ var SandboxBuilder = class {
7426
7444
  sensitivityLevel: metadata?.sensitivityLevel
7427
7445
  });
7428
7446
  }
7447
+ const emit = createEventEmitter(config.eventCallback);
7429
7448
  const handlerContext = {
7430
7449
  metadata,
7431
- requestContext: config.requestContext
7450
+ requestContext: config.requestContext,
7451
+ emit
7432
7452
  };
7433
7453
  const toolCallStartTime = Date.now();
7434
7454
  let result;
7435
7455
  let toolCallError;
7456
+ emit(createToolStartEvent(func.name, group.name, input));
7436
7457
  try {
7437
7458
  result = await handler(input, handlerContext);
7438
7459
  } catch (error) {
7439
7460
  toolCallError = error instanceof Error ? error : new Error(String(error));
7440
7461
  throw error;
7441
7462
  } finally {
7463
+ const duration = Date.now() - toolCallStartTime;
7464
+ emit(createToolEndEvent(func.name, group.name, toolCallError ? void 0 : result, duration, !toolCallError, toolCallError?.message));
7442
7465
  if (config.onToolCall) {
7443
- const duration = Date.now() - toolCallStartTime;
7444
7466
  config.onToolCall({
7445
7467
  toolName: func.name,
7446
7468
  apiGroup: group.name,
@@ -11268,7 +11290,8 @@ async function handleExecute(ctx, executor, stateManager, config, auditSink, ses
11268
11290
  path: ctx.path,
11269
11291
  method: ctx.method
11270
11292
  },
11271
- onToolCall
11293
+ onToolCall,
11294
+ eventCallback: requestConfig.eventCallback
11272
11295
  };
11273
11296
  let hintMap;
11274
11297
  const prelimExecutionId = crypto.randomUUID();