@quantish/agent 0.1.4 → 0.1.5

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 +16 -3
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -3162,13 +3162,16 @@ var Agent = class {
3162
3162
  }
3163
3163
  /**
3164
3164
  * Run the agent with a user message (supports streaming)
3165
+ * @param userMessage - The user's input message
3166
+ * @param options - Optional configuration including abort signal
3165
3167
  */
3166
- async run(userMessage) {
3168
+ async run(userMessage, options) {
3167
3169
  const maxIterations = this.config.maxIterations ?? 15;
3168
3170
  const model = this.config.model ?? "claude-sonnet-4-5-20250929";
3169
3171
  const maxTokens = this.config.maxTokens ?? 8192;
3170
3172
  const systemPrompt = this.config.systemPrompt ?? DEFAULT_SYSTEM_PROMPT;
3171
3173
  const useStreaming = this.config.streaming ?? true;
3174
+ const signal = options?.signal;
3172
3175
  const allTools = await this.getAllTools();
3173
3176
  const contextManagement = this.config.contextEditing && this.config.contextEditing.length > 0 ? { edits: this.config.contextEditing } : void 0;
3174
3177
  const contextMessage = `[Working directory: ${this.workingDirectory}]
@@ -3182,6 +3185,9 @@ ${userMessage}`;
3182
3185
  let iterations = 0;
3183
3186
  let finalText = "";
3184
3187
  while (iterations < maxIterations) {
3188
+ if (signal?.aborted) {
3189
+ throw new Error("Operation aborted by user");
3190
+ }
3185
3191
  iterations++;
3186
3192
  this.config.onStreamStart?.();
3187
3193
  let response;
@@ -3206,8 +3212,12 @@ ${userMessage}`;
3206
3212
  if (contextManagement) {
3207
3213
  streamOptions.context_management = contextManagement;
3208
3214
  }
3209
- const stream = this.anthropic.messages.stream(streamOptions);
3215
+ const stream = this.anthropic.messages.stream(streamOptions, { signal });
3210
3216
  for await (const event of stream) {
3217
+ if (signal?.aborted) {
3218
+ stream.controller.abort();
3219
+ throw new Error("Operation aborted by user");
3220
+ }
3211
3221
  if (event.type === "content_block_delta") {
3212
3222
  const delta = event.delta;
3213
3223
  if (delta.type === "text_delta" && delta.text) {
@@ -3272,6 +3282,9 @@ ${userMessage}`;
3272
3282
  }
3273
3283
  const toolResults = [];
3274
3284
  for (const toolUse of toolUses) {
3285
+ if (signal?.aborted) {
3286
+ throw new Error("Operation aborted by user");
3287
+ }
3275
3288
  this.config.onToolCall?.(toolUse.name, toolUse.input);
3276
3289
  await new Promise((resolve2) => setImmediate(resolve2));
3277
3290
  const { result, source } = await this.executeTool(
@@ -3930,7 +3943,7 @@ Last API Call Cost:
3930
3943
  completedToolCalls.current = [];
3931
3944
  abortController.current = new AbortController();
3932
3945
  try {
3933
- const result = await agent.run(trimmed);
3946
+ const result = await agent.run(trimmed, { signal: abortController.current?.signal });
3934
3947
  if (isInterrupted) {
3935
3948
  setMessages((prev) => [...prev, {
3936
3949
  role: "system",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quantish/agent",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "description": "AI-powered agent for building trading bots on Polymarket",
5
5
  "type": "module",
6
6
  "bin": {