History

fix: handle Claude Agent SDK 0.3.x system messages to stop runtime-warning flood (#2872)

Abdul Azeez committed 5 months ago

Commit e1ce9f81 parent 602148f3 files · +58 −0Browse files

Unified · Split

3 files
  1. apps/server/src/orchestration/Layers/ProviderRuntimeIngestion.ts +20 −0
  2. apps/server/src/provider/Layers/ClaudeAdapter.ts +21 −0
  3. packages/contracts/src/providerRuntime.ts +17 −0
apps/server/src/orchestration/Layers/ProviderRuntimeIngestion.ts+20−0
@@ -344,6 +344,26 @@ function runtimeEventToActivities( · 343 unmodified lines
344344 ];
345345 }
346346
347+ case "tool.denied": {
348+ return [
349+ {
350+ id: event.eventId,
351+ createdAt: event.createdAt,
352+ tone: "error",
353+ kind: "tool.denied",
354+ summary: `Tool denied: ${event.payload.toolName}`,
355+ payload: {
356+ toolName: event.payload.toolName,
357+ ...(event.payload.toolUseId ? { toolUseId: event.payload.toolUseId } : {}),
358+ ...(event.payload.reason ? { detail: truncateDetail(event.payload.reason) } : {}),
359+ ...(event.payload.agentId ? { agentId: event.payload.agentId } : {}),
360+ },
361+ turnId: toTurnId(event.turnId) ?? null,
362+ ...maybeSequence,
363+ },
364+ ];
365+ }
366+
347367 case "runtime.warning": {
348368 return [
349369 {
apps/server/src/provider/Layers/ClaudeAdapter.ts+21−0
@@ -2267,6 +2267,27 @@ export const makeClaudeAdapter = Effect.fn("makeClaudeAdapter")(function* ( · 2266 unmodified lines
22672267 },
22682268 });
22692269 return;
2270+ case "thinking_tokens":
2271+ return;
2272+ case "permission_denied":
2273+ yield* offerRuntimeEvent({
2274+ ...base,
2275+ type: "tool.denied",
2276+ payload: {
2277+ toolName: message.tool_name,
2278+ ...(message.tool_use_id ? { toolUseId: message.tool_use_id } : {}),
2279+ ...(message.decision_reason ? { reason: message.decision_reason } : {}),
2280+ ...(message.agent_id ? { agentId: message.agent_id } : {}),
2281+ },
2282+ });
2283+ return;
2284+ case "mirror_error":
2285+ yield* emitRuntimeError(
2286+ context,
2287+ `Claude workspace mirror error: ${message.error}`,
2288+ message,
2289+ );
2290+ return;
22702291 default:
22712292 yield* emitRuntimeWarning(
22722293 context,
packages/contracts/src/providerRuntime.ts+17−0
@@ -241,6 +241,7 @@ const ModelReroutedType = Schema.Literal("model.rerouted"); · 240 unmodified lines
241241 const ConfigWarningType = Schema.Literal("config.warning");
242242 const DeprecationNoticeType = Schema.Literal("deprecation.notice");
243243 const FilesPersistedType = Schema.Literal("files.persisted");
244+const ToolDeniedType = Schema.Literal("tool.denied");
244245 const RuntimeWarningType = Schema.Literal("runtime.warning");
245246 const RuntimeErrorType = Schema.Literal("runtime.error");
246247
@@ -589,6 +590,14 @@ const FilesPersistedPayload = Schema.Struct({ · 342 unmodified lines
589590 });
590591 export type FilesPersistedPayload = typeof FilesPersistedPayload.Type;
591592
593+const ToolDeniedPayload = Schema.Struct({
594+ toolName: TrimmedNonEmptyStringSchema,
595+ toolUseId: Schema.optional(TrimmedNonEmptyStringSchema),
596+ reason: Schema.optional(TrimmedNonEmptyStringSchema),
597+ agentId: Schema.optional(TrimmedNonEmptyStringSchema),
598+});
599+export type ToolDeniedPayload = typeof ToolDeniedPayload.Type;
600+
592601 const RuntimeWarningPayload = Schema.Struct({
593602 message: TrimmedNonEmptyStringSchema,
594603 detail: Schema.optional(Schema.Unknown),
@@ -934,6 +943,13 @@ const ProviderRuntimeFilesPersistedEvent = Schema.Struct({ · 339 unmodified lines
934943 });
935944 export type ProviderRuntimeFilesPersistedEvent = typeof ProviderRuntimeFilesPersistedEvent.Type;
936945
946+const ProviderRuntimeToolDeniedEvent = Schema.Struct({
947+ ...ProviderRuntimeEventBase.fields,
948+ type: ToolDeniedType,
949+ payload: ToolDeniedPayload,
950+});
951+export type ProviderRuntimeToolDeniedEvent = typeof ProviderRuntimeToolDeniedEvent.Type;
952+
937953 const ProviderRuntimeWarningEvent = Schema.Struct({
938954 ...ProviderRuntimeEventBase.fields,
939955 type: RuntimeWarningType,
@@ -994,6 +1010,7 @@ export const ProviderRuntimeEventV2 = Schema.Union([ · 54 unmodified lines
9941010 ProviderRuntimeConfigWarningEvent,
9951011 ProviderRuntimeDeprecationNoticeEvent,
9961012 ProviderRuntimeFilesPersistedEvent,
1013+ ProviderRuntimeToolDeniedEvent,
9971014 ProviderRuntimeWarningEvent,
9981015 ProviderRuntimeErrorEvent,
9991016 ]);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t