@salesforce/sfdx-agent-harness-mastra 0.65.0 → 0.66.0

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
@@ -3,6 +3,11 @@
3
3
  All notable changes to `@salesforce/sfdx-agent-harness-mastra` are documented in this file.
4
4
  Format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
5
5
 
6
+ ## [0.66.0] - 2026-09-02
7
+
8
+ ### Features
9
+ - **agent-sdk,harness-mastra,harness-claude,harness-openai**: classify context-window overflow as a typed CONTEXT_LENGTH_EXCEEDED error @W-24074717@ ([#788](https://github.com/forcedotcom/agentic-dx/pull/788))
10
+
6
11
  ## [0.65.0] - 2026-09-02
7
12
 
8
13
  _No changes — released alongside dependent packages._
@@ -2,6 +2,7 @@
2
2
  * Copyright 2026, Salesforce, Inc. All rights reserved.
3
3
  * See LICENSE.txt for license terms.
4
4
  */
5
+ import { CONTEXT_LENGTH_EXCEEDED_CODE, createContextLengthExceededError } from '@salesforce/sfdx-agent-sdk';
5
6
  import { isClassifiedStreamError } from './stream-errors.js';
6
7
  /**
7
8
  * Adapts Mastra `ChunkType` stream events to our {@link ChatEvent} discriminated union.
@@ -153,10 +154,19 @@ export class MastraEventAdapter {
153
154
  }
154
155
  case 'error': {
155
156
  const rawError = chunk.payload.error;
157
+ const code = isClassifiedStreamError(rawError) ? rawError.code : undefined;
158
+ const baseError = rawError instanceof Error ? rawError : new Error(String(rawError));
159
+ // Context-window overflow is the one classified error we upgrade to
160
+ // the SDK's typed `AgentSDKError(CONTEXT_LENGTH_EXCEEDED)` so the
161
+ // in-stream signal matches the pre-flight throw and carries the
162
+ // actionable message; the raw ValidationStreamError rides on `.cause`.
163
+ if (code === CONTEXT_LENGTH_EXCEEDED_CODE) {
164
+ return { type: 'error', error: createContextLengthExceededError(baseError), code };
165
+ }
156
166
  return {
157
167
  type: 'error',
158
- error: rawError instanceof Error ? rawError : new Error(String(rawError)),
159
- ...(isClassifiedStreamError(rawError) ? { code: rawError.code } : {}),
168
+ error: baseError,
169
+ ...(code !== undefined ? { code } : {}),
160
170
  };
161
171
  }
162
172
  case 'tripwire':
@@ -1,6 +1,13 @@
1
1
  export declare const NETWORK_ERROR_CODE: 'network-error';
2
2
  export declare const EMPTY_STREAM_ERROR_CODE: 'empty-stream';
3
- export declare const CONTEXT_OVERFLOW_ERROR_CODE: 'context-window-exceeded';
3
+ /**
4
+ * The overflow `ErrorEvent.code`. Aliased to the SDK-owned
5
+ * {@link CONTEXT_LENGTH_EXCEEDED_CODE} so this harness and the cross-harness
6
+ * contract can never drift on the wire value; the adapter upgrades a
7
+ * ValidationStreamError carrying this code to the typed
8
+ * `AgentSDKError(CONTEXT_LENGTH_EXCEEDED)` before it reaches the consumer.
9
+ */
10
+ export declare const CONTEXT_OVERFLOW_ERROR_CODE: "context-window-exceeded";
4
11
  export declare const VALIDATION_ERROR_CODE: 'validation-error';
5
12
  export declare const GATEWAY_RESPONSE_ERROR_CODE: 'gateway-error';
6
13
  /**
@@ -2,9 +2,17 @@
2
2
  * Copyright 2026, Salesforce, Inc. All rights reserved.
3
3
  * See LICENSE.txt for license terms.
4
4
  */
5
+ import { CONTEXT_LENGTH_EXCEEDED_CODE, isContextWindowOverflowMessage } from '@salesforce/sfdx-agent-sdk';
5
6
  export const NETWORK_ERROR_CODE = 'network-error';
6
7
  export const EMPTY_STREAM_ERROR_CODE = 'empty-stream';
7
- export const CONTEXT_OVERFLOW_ERROR_CODE = 'context-window-exceeded';
8
+ /**
9
+ * The overflow `ErrorEvent.code`. Aliased to the SDK-owned
10
+ * {@link CONTEXT_LENGTH_EXCEEDED_CODE} so this harness and the cross-harness
11
+ * contract can never drift on the wire value; the adapter upgrades a
12
+ * ValidationStreamError carrying this code to the typed
13
+ * `AgentSDKError(CONTEXT_LENGTH_EXCEEDED)` before it reaches the consumer.
14
+ */
15
+ export const CONTEXT_OVERFLOW_ERROR_CODE = CONTEXT_LENGTH_EXCEEDED_CODE;
8
16
  export const VALIDATION_ERROR_CODE = 'validation-error';
9
17
  export const GATEWAY_RESPONSE_ERROR_CODE = 'gateway-error';
10
18
  /**
@@ -109,12 +117,6 @@ export function isStreamTransportError(error) {
109
117
  }
110
118
  return false;
111
119
  }
112
- /**
113
- * Messages Bedrock / Anthropic use for a context-window overflow — the subset of
114
- * `ValidationException` worth surfacing with the more specific
115
- * `context-window-exceeded` code (ties into spike item 04).
116
- */
117
- const CONTEXT_OVERFLOW_PATTERNS = /input is too long|prompt is too long|too many (input )?tokens|maximum context length|context (window|length)|exceed(s|ed)? (the )?(maximum )?context/i;
118
120
  /**
119
121
  * Recognizes the Bedrock `ValidationException` shape (8d), walking the `cause`
120
122
  * chain and duck-typing the several ways `@anthropic-ai/bedrock-sdk` /
@@ -131,7 +133,7 @@ export function recognizeBedrockValidationError(error) {
131
133
  seen.add(current);
132
134
  const message = extractValidationExceptionMessage(current);
133
135
  if (message !== undefined) {
134
- const code = CONTEXT_OVERFLOW_PATTERNS.test(message) ? CONTEXT_OVERFLOW_ERROR_CODE : VALIDATION_ERROR_CODE;
136
+ const code = isContextWindowOverflowMessage(message) ? CONTEXT_OVERFLOW_ERROR_CODE : VALIDATION_ERROR_CODE;
135
137
  return new ValidationStreamError(message, code);
136
138
  }
137
139
  current = current.cause;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce/sfdx-agent-harness-mastra",
3
- "version": "0.65.0",
3
+ "version": "0.66.0",
4
4
  "description": "Mastra-backed AgentHarness implementation for @salesforce/sfdx-agent-sdk",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -42,12 +42,12 @@
42
42
  "openai": "^7.0.0"
43
43
  },
44
44
  "peerDependencies": {
45
- "@salesforce/sfdx-agent-sdk": "0.66.0"
45
+ "@salesforce/sfdx-agent-sdk": "0.67.0"
46
46
  },
47
47
  "devDependencies": {
48
48
  "@eslint/js": "^10.0.1",
49
49
  "@salesforce/harness-conformance": "0.0.1",
50
- "@salesforce/sfdx-agent-sdk": "0.66.0",
50
+ "@salesforce/sfdx-agent-sdk": "0.67.0",
51
51
  "@types/node": "^22.20.1",
52
52
  "@vitest/coverage-istanbul": "^4.1.10",
53
53
  "@vitest/eslint-plugin": "^1.6.27",