@cloudbase/agent-agents 0.0.6 → 0.0.8

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/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @cloudbase/agent-agents
2
2
 
3
+ ## 1.0.1-alpha.4
4
+
5
+ ### Patch Changes
6
+
7
+ - alpha release 0.1.2-alpha.1
8
+ - Update all public packages to version 0.1.2-alpha.1
9
+ - Trigger automated alpha release workflow
10
+ - Includes latest features and improvements
11
+
12
+ - Updated dependencies
13
+ - @cloudbase/agent-tools@1.0.1-alpha.4
14
+
3
15
  ## 0.0.11-alpha.3
4
16
 
5
17
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -2743,6 +2743,7 @@ interface RunOptions<TState extends StateConstraint = StateConstraint> {
2743
2743
  interruptId: string;
2744
2744
  payload: string;
2745
2745
  };
2746
+ signal?: AbortSignal;
2746
2747
  onEvent?: (event: any) => void;
2747
2748
  }
2748
2749
  interface RunContext<TState = unknown> {
@@ -3421,6 +3422,11 @@ interface ChatCompletionParams {
3421
3422
  };
3422
3423
  stream?: boolean;
3423
3424
  stop?: string[];
3425
+ /**
3426
+ * AbortSignal for cancelling the LLM request.
3427
+ * When aborted, the underlying HTTP request will be cancelled.
3428
+ */
3429
+ signal?: AbortSignal;
3424
3430
  }
3425
3431
  interface ToolDefinition {
3426
3432
  type: 'function';
@@ -3491,7 +3497,7 @@ interface ModelProviderConfig {
3491
3497
  rejectUnauthorized?: boolean;
3492
3498
  }
3493
3499
  interface ModelProviderError extends Error {
3494
- type: 'authentication' | 'rate_limit' | 'quota_exceeded' | 'invalid_request' | 'server_error' | 'timeout' | 'unknown';
3500
+ type: 'authentication' | 'rate_limit' | 'quota_exceeded' | 'invalid_request' | 'server_error' | 'timeout' | 'aborted' | 'unknown';
3495
3501
  status?: number;
3496
3502
  code?: string;
3497
3503
  details?: any;
package/dist/index.d.ts CHANGED
@@ -2743,6 +2743,7 @@ interface RunOptions<TState extends StateConstraint = StateConstraint> {
2743
2743
  interruptId: string;
2744
2744
  payload: string;
2745
2745
  };
2746
+ signal?: AbortSignal;
2746
2747
  onEvent?: (event: any) => void;
2747
2748
  }
2748
2749
  interface RunContext<TState = unknown> {
@@ -3421,6 +3422,11 @@ interface ChatCompletionParams {
3421
3422
  };
3422
3423
  stream?: boolean;
3423
3424
  stop?: string[];
3425
+ /**
3426
+ * AbortSignal for cancelling the LLM request.
3427
+ * When aborted, the underlying HTTP request will be cancelled.
3428
+ */
3429
+ signal?: AbortSignal;
3424
3430
  }
3425
3431
  interface ToolDefinition {
3426
3432
  type: 'function';
@@ -3491,7 +3497,7 @@ interface ModelProviderConfig {
3491
3497
  rejectUnauthorized?: boolean;
3492
3498
  }
3493
3499
  interface ModelProviderError extends Error {
3494
- type: 'authentication' | 'rate_limit' | 'quota_exceeded' | 'invalid_request' | 'server_error' | 'timeout' | 'unknown';
3500
+ type: 'authentication' | 'rate_limit' | 'quota_exceeded' | 'invalid_request' | 'server_error' | 'timeout' | 'aborted' | 'unknown';
3495
3501
  status?: number;
3496
3502
  code?: string;
3497
3503
  details?: any;
package/dist/index.js CHANGED
@@ -2020,6 +2020,11 @@ var AgentExecutor = class {
2020
2020
  const customHandler = this.config.controlFlow?.customHandler;
2021
2021
  while (maxIterations === void 0 || iteration < maxIterations) {
2022
2022
  iteration++;
2023
+ if (options?.signal?.aborted) {
2024
+ throw new Error(
2025
+ `Run aborted: ${options.signal.reason || "AbortSignal was aborted"}`
2026
+ );
2027
+ }
2023
2028
  const controlResult = await this.checkControlFlow(
2024
2029
  customHandler,
2025
2030
  context,
@@ -2084,7 +2089,8 @@ var AgentExecutor = class {
2084
2089
  );
2085
2090
  const streamResult = await this.processStreamingResponse(
2086
2091
  llmResponse,
2087
- eventEmitter
2092
+ eventEmitter,
2093
+ options
2088
2094
  );
2089
2095
  const assistantMessage = await this.saveAssistantMessage(
2090
2096
  streamResult.content,
@@ -2456,6 +2462,9 @@ var AgentExecutor = class {
2456
2462
  requestParams.tools = toolDefinitions;
2457
2463
  requestParams.tool_choice = "auto";
2458
2464
  }
2465
+ if (options?.signal) {
2466
+ requestParams.signal = options.signal;
2467
+ }
2459
2468
  return this.modelProvider.chat.completions.stream(requestParams);
2460
2469
  }
2461
2470
  /**
@@ -4247,6 +4256,17 @@ var Agent = class {
4247
4256
  }
4248
4257
  }
4249
4258
  };
4259
+ if (options?.signal?.aborted) {
4260
+ throw new ExecutionError(
4261
+ "Run aborted before start",
4262
+ { reason: options.signal.reason || "AbortSignal was already aborted" }
4263
+ );
4264
+ }
4265
+ const abortHandler = () => {
4266
+ this.isRunning = false;
4267
+ this.state.status = "idle";
4268
+ };
4269
+ options?.signal?.addEventListener("abort", abortHandler);
4250
4270
  eventEmitter.emit("RUN_STARTED" /* RUN_STARTED */, {
4251
4271
  type: "RUN_STARTED" /* RUN_STARTED */,
4252
4272
  threadId: conversationId,
@@ -4260,6 +4280,12 @@ var Agent = class {
4260
4280
  this.state.status = "running";
4261
4281
  this.state.runId = runId;
4262
4282
  this.state.conversationId = conversationId;
4283
+ if (options?.signal?.aborted) {
4284
+ throw new ExecutionError(
4285
+ "Run aborted",
4286
+ { reason: options.signal.reason || "AbortSignal was aborted" }
4287
+ );
4288
+ }
4263
4289
  if (options?.resume) {
4264
4290
  try {
4265
4291
  const resumePayload = JSON.parse(options.resume.payload);
@@ -4279,12 +4305,24 @@ var Agent = class {
4279
4305
  state: this.state
4280
4306
  });
4281
4307
  const context = await this.createRunContext(input, state, options);
4308
+ if (options?.signal?.aborted) {
4309
+ throw new ExecutionError(
4310
+ "Run aborted",
4311
+ { reason: options.signal.reason || "AbortSignal was aborted" }
4312
+ );
4313
+ }
4282
4314
  const result = await this.executeAgentCore(
4283
4315
  eventEmitter,
4284
4316
  context,
4285
4317
  validatedOptions,
4286
4318
  true
4287
4319
  );
4320
+ if (options?.signal?.aborted) {
4321
+ throw new ExecutionError(
4322
+ "Run aborted",
4323
+ { reason: options.signal.reason || "AbortSignal was aborted" }
4324
+ );
4325
+ }
4288
4326
  if (result && result.metadata && result.metadata.outcome !== "interrupt") {
4289
4327
  eventEmitter.emit("RUN_FINISHED" /* RUN_FINISHED */, {
4290
4328
  type: "RUN_FINISHED" /* RUN_FINISHED */,
@@ -4313,6 +4351,10 @@ var Agent = class {
4313
4351
  this.isRunning = false;
4314
4352
  this.state.status = "error";
4315
4353
  throw agentError;
4354
+ } finally {
4355
+ if (options?.signal) {
4356
+ options.signal.removeEventListener("abort", abortHandler);
4357
+ }
4316
4358
  }
4317
4359
  }
4318
4360
  // Streaming run method - Returns AsyncIterator (no RxJS dependency)
@@ -5124,8 +5166,12 @@ var OpenAIProvider = class extends BaseModelProvider {
5124
5166
  async createCompletion(params) {
5125
5167
  try {
5126
5168
  const openaiParams = this.convertToOpenAIParams(params);
5169
+ const requestOptions = {};
5170
+ if (params.signal) {
5171
+ requestOptions.signal = params.signal;
5172
+ }
5127
5173
  const response = await this.withRetry(async () => {
5128
- return await this.client.chat.completions.create(openaiParams);
5174
+ return await this.client.chat.completions.create(openaiParams, requestOptions);
5129
5175
  });
5130
5176
  return this.convertFromOpenAIResponse(response);
5131
5177
  } catch (error) {
@@ -5139,10 +5185,14 @@ var OpenAIProvider = class extends BaseModelProvider {
5139
5185
  async *createStream(params) {
5140
5186
  try {
5141
5187
  const openaiParams = this.convertToOpenAIParams(params);
5188
+ const requestOptions = {};
5189
+ if (params.signal) {
5190
+ requestOptions.signal = params.signal;
5191
+ }
5142
5192
  const stream = await this.client.chat.completions.create({
5143
5193
  ...openaiParams,
5144
5194
  stream: true
5145
- });
5195
+ }, requestOptions);
5146
5196
  if (Symbol.asyncIterator in stream) {
5147
5197
  for await (const chunk of stream) {
5148
5198
  yield this.convertFromOpenAIChunk(chunk);
@@ -5209,6 +5259,9 @@ var OpenAIProvider = class extends BaseModelProvider {
5209
5259
  // Handle OpenAI-specific errors
5210
5260
  handleOpenAIError(error) {
5211
5261
  if (error instanceof Error) {
5262
+ if (error.name === "AbortError" || error.message.includes("abort")) {
5263
+ return this.createError("Request aborted", "aborted", error);
5264
+ }
5212
5265
  if (error.message.includes("401") || error.message.includes("Unauthorized")) {
5213
5266
  return this.createError("Invalid API key", "authentication", error);
5214
5267
  }
@@ -5370,8 +5423,12 @@ var AnthropicProvider = class extends BaseModelProvider {
5370
5423
  async createCompletion(params) {
5371
5424
  try {
5372
5425
  const anthropicParams = this.convertToAnthropicParams(params);
5426
+ const requestOptions = {};
5427
+ if (params.signal) {
5428
+ requestOptions.signal = params.signal;
5429
+ }
5373
5430
  const response = await this.withRetry(async () => {
5374
- return await this.client.messages.create(anthropicParams);
5431
+ return await this.client.messages.create(anthropicParams, requestOptions);
5375
5432
  });
5376
5433
  return this.convertFromAnthropicResponse(response, params.model);
5377
5434
  } catch (error) {
@@ -5386,7 +5443,11 @@ var AnthropicProvider = class extends BaseModelProvider {
5386
5443
  try {
5387
5444
  const anthropicParams = this.convertToAnthropicParams(params);
5388
5445
  anthropicParams.stream = true;
5389
- const stream = await this.client.messages.create(anthropicParams);
5446
+ const requestOptions = {};
5447
+ if (params.signal) {
5448
+ requestOptions.signal = params.signal;
5449
+ }
5450
+ const stream = await this.client.messages.create(anthropicParams, requestOptions);
5390
5451
  if (Symbol.asyncIterator in stream) {
5391
5452
  for await (const chunk of stream) {
5392
5453
  yield this.convertFromAnthropicChunk(chunk, params.model);
@@ -5492,6 +5553,9 @@ var AnthropicProvider = class extends BaseModelProvider {
5492
5553
  // Handle Anthropic-specific errors
5493
5554
  handleAnthropicError(error) {
5494
5555
  if (error instanceof Error) {
5556
+ if (error.name === "AbortError" || error.message.includes("abort")) {
5557
+ return this.createError("Request aborted", "aborted", error);
5558
+ }
5495
5559
  if (error.message.includes("401") || error.message.includes("Unauthorized")) {
5496
5560
  return this.createError("Invalid API key", "authentication", error);
5497
5561
  }