@yolk-sdk/harness 0.1.0-canary.85 → 0.1.0-canary.87
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/outcome.d.mts.map +1 -1
- package/dist/outcome.mjs +1 -1
- package/dist/outcome.mjs.map +1 -1
- package/package.json +2 -2
- package/src/outcome.ts +7 -0
package/dist/outcome.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"outcome.d.mts","names":[],"sources":["../src/outcome.ts"],"mappings":";;;;;KAkCY,wBAAA;EAAA,SACG,IAAA;EAAA,SAA4B,QAAA,EAAU,aAAa,CAAC,YAAA;AAAA;EAAA,SACpD,IAAA;AAAA;AAAA,cAEF,wBAAA;EAAA;;uBAHwC,aAAA,CAAc,YAAA;EAAA;EAAA;;;;;uBAAd,aAAA,CAAc,YAAA;EAAA;IAAA;;;;;;;;;;2BAAd,aAAA,CAAc,YAAA;MAAA;MAAA;;;;;;;2BAAd,aAAA,CAAc,YAAA;MAAA;MAAA;;;;;;KAKvD,WAAA,GAAc,IAAA,CAAK,UAAA;EAC7B,SAAA;IAAA,SACW,iBAAA;IAAA,SACA,gBAAA,EAAkB,eAAA;IAAA,SAClB,SAAA,EAAW,eAAA;IAAA,SACX,KAAA,EAAO,eAAA;IAAA,SACP,UAAA,EAAY,eAAA;EAAA;EAEvB,KAAA;IAAA,SACW,KAAA,EAAO,cAAA;EAAA;EAElB,QAAA;IAAA,SACW,KAAA,EAAO,cAAA;IAAA,SACP,gBAAA,EAAkB,eAAA;IAAA,SAClB,SAAA,EAAW,eAAA;IAAA,SACX,KAAA,EAAO,eAAA;IAAA,SACP,UAAA,EAAY,eAAA;EAAA;EAEvB,WAAA;IAAA,SACW,KAAA,EAAO,cAAA;EAAA;EAElB,SAAA;IAAA,SACW,QAAA,EAAU,aAAA,CAAc,YAAA;IAAA,SACxB,yBAAA;EAAA;EAEX,aAAA;IAAA,SACW,QAAA,EAAU,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AA;AAAA,MAC1D,MAAA,CAAO,MAAA,CAAO,CAAA,GAAI,OAAA,CAAQ,SAAA;EAAA,SAAsB,IAAA;AAAA,IAAqB,CAAA,EAAG,CAAA"}
|
package/dist/outcome.mjs
CHANGED
|
@@ -121,7 +121,7 @@ const attemptToolBatch = (config, options) => {
|
|
|
121
121
|
}));
|
|
122
122
|
};
|
|
123
123
|
const HitlMatch = HitlMatch$1;
|
|
124
|
-
const hitlResponseMatchesRequest = (response, request) => Match.value(response).pipe(Match.tag("ToolApprovalResponse", (current) => Predicate.isTagged(request, "ToolApprovalRequest") && current.requestId === request.requestId && current.toolCallId === request.toolCallId), Match.tag("QuestionResponse", (current) => Predicate.isTagged(request, "QuestionRequest") && current.requestId === request.requestId && current.toolCallId === request.toolCallId), Match.tag("InputResponse", (current) => Predicate.isTagged(request, "InputRequest") && current.requestId === request.requestId && current.toolCallId === request.toolCallId), Match.exhaustive);
|
|
124
|
+
const hitlResponseMatchesRequest = (response, request) => Match.value(response).pipe(Match.tag("ToolApprovalResponse", (current) => Predicate.isTagged(request, "ToolApprovalRequest") && current.requestId === request.requestId && current.toolCallId === request.toolCallId), Match.tag("QuestionResponse", (current) => Predicate.isTagged(request, "QuestionRequest") && current.requestId === request.requestId && current.toolCallId === request.toolCallId), Match.tag("InputResponse", (current) => Predicate.isTagged(request, "InputRequest") && current.requestId === request.requestId && current.toolCallId === request.toolCallId), Match.tag("InteractionResponse", (current) => Predicate.isTagged(request, "InteractionRequest") && current.requestId === request.requestId && current.toolCallId === request.toolCallId), Match.exhaustive);
|
|
125
125
|
const matchHitlResponse = (pending, response) => {
|
|
126
126
|
const matched = pending.find((request) => hitlResponseMatchesRequest(response, request));
|
|
127
127
|
return matched === void 0 ? HitlMatch.Mismatch() : HitlMatch.Match({ requestId: matched.requestId });
|
package/dist/outcome.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"outcome.mjs","names":["overflowCompactionResult","stepOutcome","hitlMatch"],"sources":["../src/outcome.ts"],"sourcesContent":["import { Effect, Match, Predicate, Stream, type Data } from 'effect'\nimport {\n HitlMatch as hitlMatch,\n OverflowCompactionResult as overflowCompactionResult,\n StepOutcome as stepOutcome\n} from './outcome-constructors-internal.ts'\nimport {\n addAgentUsage,\n zeroAgentUsage,\n type AgentEvent,\n type AgentMessage,\n type AgentUsage,\n type HitlRequest,\n type HitlResponse\n} from '@yolk-sdk/agent/protocol'\nimport {\n collectModelTurnAttempt,\n LLMError,\n runModelTurn,\n runToolBatch,\n type AgentLoopError,\n type ContextTransformer,\n type LLMProvider,\n type LoopConfig,\n type ModelTurnConfig,\n type ModelTurnResult,\n type ToolBatchConfig,\n type ToolExecutor\n} from '@yolk-sdk/agent/loop'\nimport {\n applyOverflowCompaction,\n isOverflowCompactionAttemptCount\n} from '@yolk-sdk/agent/compaction'\n\nexport type OverflowCompactionResult =\n | { readonly _tag: 'Compacted'; readonly messages: ReadonlyArray<AgentMessage> }\n | { readonly _tag: 'Skipped' }\n\nexport const OverflowCompactionResult = overflowCompactionResult\n\nexport type StepOutcome = Data.TaggedEnum<{\n Completed: {\n readonly needsContinuation: boolean\n readonly assistantMessage: ModelTurnResult['assistantMessage']\n readonly toolCalls: ModelTurnResult['toolCalls']\n readonly usage: ModelTurnResult['usage']\n readonly stopReason: ModelTurnResult['stopReason']\n }\n Retry: {\n readonly error: AgentLoopError\n }\n Continue: {\n readonly error: AgentLoopError\n readonly assistantMessage: ModelTurnResult['assistantMessage']\n readonly toolCalls: ModelTurnResult['toolCalls']\n readonly usage: ModelTurnResult['usage']\n readonly stopReason: ModelTurnResult['stopReason']\n }\n RecoverFull: {\n readonly error: AgentLoopError\n }\n Compacted: {\n readonly messages: ReadonlyArray<AgentMessage>\n readonly overflowCompactionAttempt: number\n }\n AwaitingInput: {\n readonly requests: ReadonlyArray<HitlRequest>\n readonly usage: AgentUsage\n }\n}>\n\nexport const StepOutcome = stepOutcome\n\nexport type CompletedTurn = Extract<StepOutcome, { readonly _tag: 'Completed' }>\n\nexport type ModelTurnOutcome = Exclude<StepOutcome, { readonly _tag: 'AwaitingInput' }>\n\nexport type ToolBatchOutcome = Extract<\n StepOutcome,\n { readonly _tag: 'Completed' | 'AwaitingInput' }\n>\n\nconst completedOutcome = (result: ModelTurnResult): CompletedTurn =>\n StepOutcome.Completed({\n needsContinuation: result.stopReason === 'tool_use',\n assistantMessage: result.assistantMessage,\n toolCalls: result.toolCalls,\n usage: result.usage,\n stopReason: result.stopReason\n })\n\nconst modelTurnResult = (result: ModelTurnResult): ModelTurnResult => ({\n assistantMessage: result.assistantMessage,\n toolCalls: result.toolCalls,\n usage: result.usage,\n stopReason: result.stopReason\n})\n\nconst invalidOverflowCompactionAttemptError = () =>\n new LLMError({\n cause: 'validation_error',\n message: 'overflowCompactionAttempt must be a finite integer >= 0',\n retryable: false\n })\n\nconst isAgentLoopError = (error: unknown): error is AgentLoopError => {\n if (!Predicate.isObjectOrArray(error) || !('_tag' in error)) {\n return false\n }\n\n const tag = error._tag\n\n return (\n tag === 'LLMError' ||\n tag === 'FauxExhaustedError' ||\n tag === 'ToolError' ||\n tag === 'ContextTransformError' ||\n tag === 'AbortError'\n )\n}\n\nconst isOverflow = (error: AgentLoopError) =>\n Match.value(error).pipe(\n Match.tag('LLMError', 'ContextTransformError', current => current.cause === 'context_overflow'),\n Match.orElse(() => false)\n )\n\nconst isMissingDone = (error: AgentLoopError) =>\n Match.value(error).pipe(\n Match.tag('LLMError', current => current.responseIssue === 'missing_done'),\n Match.orElse(() => false)\n )\n\nconst isRetryableLlm = (\n error: AgentLoopError\n): error is Extract<AgentLoopError, { _tag: 'LLMError' }> =>\n Predicate.isTagged(error, 'LLMError') && error.retryable\n\nconst classifyModelTurnFailure = <E2, R2>(input: {\n readonly error: AgentLoopError\n readonly collected: ModelTurnResult\n readonly outputStarted: boolean\n readonly messages: ReadonlyArray<AgentMessage>\n readonly overflowCompactionAttempt: number\n readonly compact?: (\n messages: ReadonlyArray<AgentMessage>\n ) => Effect.Effect<OverflowCompactionResult, E2, R2>\n}): Effect.Effect<ModelTurnOutcome, AgentLoopError | E2, R2> => {\n if (isOverflow(input.error)) {\n if (input.compact === undefined) {\n return Effect.fail(input.error)\n }\n\n return applyOverflowCompaction({\n compact: input.compact,\n messages: input.messages,\n attempt: input.overflowCompactionAttempt,\n outputStarted: input.outputStarted\n }).pipe(\n Effect.flatMap(result =>\n Match.value(result).pipe(\n Match.tag('Compacted', current =>\n Effect.succeed(\n StepOutcome.Compacted({\n messages: current.messages,\n overflowCompactionAttempt: input.overflowCompactionAttempt + 1\n })\n )\n ),\n Match.orElse(() => Effect.fail(input.error))\n )\n )\n )\n }\n\n if (isMissingDone(input.error) && !input.outputStarted) {\n return Effect.succeed(StepOutcome.RecoverFull({ error: input.error }))\n }\n\n if (isMissingDone(input.error) && input.outputStarted) {\n return Effect.succeed(\n StepOutcome.Continue({\n error: input.error,\n ...modelTurnResult(input.collected)\n })\n )\n }\n\n if (isRetryableLlm(input.error) && !input.outputStarted) {\n if (input.error.cause === 'invalid_response') {\n return Effect.succeed(StepOutcome.RecoverFull({ error: input.error }))\n }\n\n return Effect.succeed(StepOutcome.Retry({ error: input.error }))\n }\n\n if (isRetryableLlm(input.error) && input.outputStarted) {\n return Effect.succeed(\n StepOutcome.Continue({\n error: input.error,\n ...modelTurnResult(input.collected)\n })\n )\n }\n\n return Effect.fail(input.error)\n}\n\nexport const attemptModelTurn = <E2 = never, R2 = never>(\n config: ModelTurnConfig,\n options?: {\n readonly onEvent?: (event: AgentEvent) => Effect.Effect<void, E2, R2>\n readonly initialUsage?: AgentUsage\n readonly overflowCompactionAttempt?: number\n readonly compact?: (\n messages: ReadonlyArray<AgentMessage>\n ) => Effect.Effect<OverflowCompactionResult, E2, R2>\n }\n): Effect.Effect<\n ModelTurnOutcome,\n AgentLoopError | E2,\n ContextTransformer | LLMProvider | LoopConfig | R2\n> =>\n Effect.gen(function* () {\n const overflowCompactionAttempt = options?.overflowCompactionAttempt ?? 0\n\n if (!isOverflowCompactionAttemptCount(overflowCompactionAttempt)) {\n return yield* Effect.fail(invalidOverflowCompactionAttemptError())\n }\n\n const outcome = yield* collectModelTurnAttempt(runModelTurn(config), {\n onEvent: options?.onEvent,\n initialUsage: options?.initialUsage\n })\n\n return yield* Match.value(outcome).pipe(\n Match.tag('Collected', current => Effect.succeed(completedOutcome(current.collection))),\n Match.tag('SinkFailed', current => Effect.fail(current.error)),\n Match.tag('StreamFailed', current => {\n if (!isAgentLoopError(current.error)) {\n return Effect.fail(current.error)\n }\n\n return classifyModelTurnFailure({\n error: current.error,\n collected: {\n assistantMessage:\n current.collection.assistantMessage ?? current.collection.partialAssistantMessage,\n toolCalls: current.collection.toolCalls,\n usage: current.collection.usage,\n stopReason: current.collection.stopReason\n },\n outputStarted: current.collection.outputStarted,\n messages: config.messages,\n overflowCompactionAttempt,\n compact: options?.compact\n })\n }),\n Match.exhaustive\n )\n })\n\ntype AttemptToolBatchFoldState = {\n requests: ReadonlyArray<HitlRequest>\n usage: AgentUsage\n toolCalls: ModelTurnResult['toolCalls']\n}\n\nexport const attemptToolBatch = <E2 = never, R2 = never>(\n config: ToolBatchConfig,\n options?: {\n readonly onEvent?: (event: AgentEvent) => Effect.Effect<void, E2, R2>\n }\n): Effect.Effect<ToolBatchOutcome, AgentLoopError | E2, LoopConfig | ToolExecutor | R2> => {\n const onEvent = options?.onEvent\n\n return runToolBatch(config).pipe(\n Stream.runFoldEffect(\n (): AttemptToolBatchFoldState => ({\n requests: [],\n usage: config.usage ?? zeroAgentUsage,\n toolCalls: []\n }),\n (acc, event) => {\n const next = Predicate.isTagged(event, 'AgentAwaitingInput')\n ? { ...acc, requests: event.requests, usage: event.usage }\n : Predicate.isTagged(event, 'UsageUpdate')\n ? { ...acc, usage: addAgentUsage(acc.usage, event.usage) }\n : Predicate.isTagged(event, 'ToolExecutionCompleted') ||\n Predicate.isTagged(event, 'ToolExecutionAccepted')\n ? { ...acc, toolCalls: [...acc.toolCalls, event.call] }\n : acc\n\n return onEvent === undefined ? Effect.succeed(next) : onEvent(event).pipe(Effect.as(next))\n }\n ),\n Effect.map((result): ToolBatchOutcome => {\n if (result.requests.length === 0) {\n const needsContinuation = result.toolCalls.length > 0\n\n return StepOutcome.Completed({\n needsContinuation,\n assistantMessage: undefined,\n toolCalls: result.toolCalls,\n usage: result.usage,\n stopReason: needsContinuation ? 'tool_use' : 'stop'\n })\n }\n\n return StepOutcome.AwaitingInput({ requests: result.requests, usage: result.usage })\n })\n )\n}\n\nexport type HitlMatch =\n | { readonly _tag: 'Match'; readonly requestId: string }\n | { readonly _tag: 'Mismatch' }\n\nexport const HitlMatch = hitlMatch\n\nconst hitlResponseMatchesRequest = (response: HitlResponse, request: HitlRequest) =>\n Match.value(response).pipe(\n Match.tag(\n 'ToolApprovalResponse',\n current =>\n Predicate.isTagged(request, 'ToolApprovalRequest') &&\n current.requestId === request.requestId &&\n current.toolCallId === request.toolCallId\n ),\n Match.tag(\n 'QuestionResponse',\n current =>\n Predicate.isTagged(request, 'QuestionRequest') &&\n current.requestId === request.requestId &&\n current.toolCallId === request.toolCallId\n ),\n Match.tag(\n 'InputResponse',\n current =>\n Predicate.isTagged(request, 'InputRequest') &&\n current.requestId === request.requestId &&\n current.toolCallId === request.toolCallId\n ),\n Match.exhaustive\n )\n\nexport const matchHitlResponse = (\n pending: ReadonlyArray<HitlRequest>,\n response: HitlResponse\n): HitlMatch => {\n const matched = pending.find(request => hitlResponseMatchesRequest(response, request))\n\n return matched === undefined\n ? HitlMatch.Mismatch()\n : HitlMatch.Match({ requestId: matched.requestId })\n}\n\nexport const resumeHitlIfMatched = <A, E, R>(input: {\n readonly pending: ReadonlyArray<HitlRequest>\n readonly response: HitlResponse\n readonly resume: (requestId: string) => Effect.Effect<A, E, R>\n}): Effect.Effect<A | Extract<HitlMatch, { readonly _tag: 'Mismatch' }>, E, R> => {\n const matched = matchHitlResponse(input.pending, input.response)\n\n return Match.value(matched).pipe(\n Match.tag('Mismatch', current => Effect.succe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atch"],"sources":["../src/outcome.ts"],"sourcesContent":["import { Effect, Match, Predicate, Stream, type Data } from 'effect'\nimport {\n HitlMatch as hitlMatch,\n OverflowCompactionResult as overflowCompactionResult,\n StepOutcome as stepOutcome\n} from './outcome-constructors-internal.ts'\nimport {\n addAgentUsage,\n zeroAgentUsage,\n type AgentEvent,\n type AgentMessage,\n type AgentUsage,\n type HitlRequest,\n type HitlResponse\n} from '@yolk-sdk/agent/protocol'\nimport {\n collectModelTurnAttempt,\n LLMError,\n runModelTurn,\n runToolBatch,\n type AgentLoopError,\n type ContextTransformer,\n type LLMProvider,\n type LoopConfig,\n type ModelTurnConfig,\n type ModelTurnResult,\n type ToolBatchConfig,\n type ToolExecutor\n} from '@yolk-sdk/agent/loop'\nimport {\n applyOverflowCompaction,\n isOverflowCompactionAttemptCount\n} from '@yolk-sdk/agent/compaction'\n\nexport type OverflowCompactionResult =\n | { readonly _tag: 'Compacted'; readonly messages: ReadonlyArray<AgentMessage> }\n | { readonly _tag: 'Skipped' }\n\nexport const OverflowCompactionResult = overflowCompactionResult\n\nexport type StepOutcome = Data.TaggedEnum<{\n Completed: {\n readonly needsContinuation: boolean\n readonly assistantMessage: ModelTurnResult['assistantMessage']\n readonly toolCalls: ModelTurnResult['toolCalls']\n readonly usage: ModelTurnResult['usage']\n readonly stopReason: ModelTurnResult['stopReason']\n }\n Retry: {\n readonly error: AgentLoopError\n }\n Continue: {\n readonly error: AgentLoopError\n readonly assistantMessage: ModelTurnResult['assistantMessage']\n readonly toolCalls: ModelTurnResult['toolCalls']\n readonly usage: ModelTurnResult['usage']\n readonly stopReason: ModelTurnResult['stopReason']\n }\n RecoverFull: {\n readonly error: AgentLoopError\n }\n Compacted: {\n readonly messages: ReadonlyArray<AgentMessage>\n readonly overflowCompactionAttempt: number\n }\n AwaitingInput: {\n readonly requests: ReadonlyArray<HitlRequest>\n readonly usage: AgentUsage\n }\n}>\n\nexport const StepOutcome = stepOutcome\n\nexport type CompletedTurn = Extract<StepOutcome, { readonly _tag: 'Completed' }>\n\nexport type ModelTurnOutcome = Exclude<StepOutcome, { readonly _tag: 'AwaitingInput' }>\n\nexport type ToolBatchOutcome = Extract<\n StepOutcome,\n { readonly _tag: 'Completed' | 'AwaitingInput' }\n>\n\nconst completedOutcome = (result: ModelTurnResult): CompletedTurn =>\n StepOutcome.Completed({\n needsContinuation: result.stopReason === 'tool_use',\n assistantMessage: result.assistantMessage,\n toolCalls: result.toolCalls,\n usage: result.usage,\n stopReason: result.stopReason\n })\n\nconst modelTurnResult = (result: ModelTurnResult): ModelTurnResult => ({\n assistantMessage: result.assistantMessage,\n toolCalls: result.toolCalls,\n usage: result.usage,\n stopReason: result.stopReason\n})\n\nconst invalidOverflowCompactionAttemptError = () =>\n new LLMError({\n cause: 'validation_error',\n message: 'overflowCompactionAttempt must be a finite integer >= 0',\n retryable: false\n })\n\nconst isAgentLoopError = (error: unknown): error is AgentLoopError => {\n if (!Predicate.isObjectOrArray(error) || !('_tag' in error)) {\n return false\n }\n\n const tag = error._tag\n\n return (\n tag === 'LLMError' ||\n tag === 'FauxExhaustedError' ||\n tag === 'ToolError' ||\n tag === 'ContextTransformError' ||\n tag === 'AbortError'\n )\n}\n\nconst isOverflow = (error: AgentLoopError) =>\n Match.value(error).pipe(\n Match.tag('LLMError', 'ContextTransformError', current => current.cause === 'context_overflow'),\n Match.orElse(() => false)\n )\n\nconst isMissingDone = (error: AgentLoopError) =>\n Match.value(error).pipe(\n Match.tag('LLMError', current => current.responseIssue === 'missing_done'),\n Match.orElse(() => false)\n )\n\nconst isRetryableLlm = (\n error: AgentLoopError\n): error is Extract<AgentLoopError, { _tag: 'LLMError' }> =>\n Predicate.isTagged(error, 'LLMError') && error.retryable\n\nconst classifyModelTurnFailure = <E2, R2>(input: {\n readonly error: AgentLoopError\n readonly collected: ModelTurnResult\n readonly outputStarted: boolean\n readonly messages: ReadonlyArray<AgentMessage>\n readonly overflowCompactionAttempt: number\n readonly compact?: (\n messages: ReadonlyArray<AgentMessage>\n ) => Effect.Effect<OverflowCompactionResult, E2, R2>\n}): Effect.Effect<ModelTurnOutcome, AgentLoopError | E2, R2> => {\n if (isOverflow(input.error)) {\n if (input.compact === undefined) {\n return Effect.fail(input.error)\n }\n\n return applyOverflowCompaction({\n compact: input.compact,\n messages: input.messages,\n attempt: input.overflowCompactionAttempt,\n outputStarted: input.outputStarted\n }).pipe(\n Effect.flatMap(result =>\n Match.value(result).pipe(\n Match.tag('Compacted', current =>\n Effect.succeed(\n StepOutcome.Compacted({\n messages: current.messages,\n overflowCompactionAttempt: input.overflowCompactionAttempt + 1\n })\n )\n ),\n Match.orElse(() => Effect.fail(input.error))\n )\n )\n )\n }\n\n if (isMissingDone(input.error) && !input.outputStarted) {\n return Effect.succeed(StepOutcome.RecoverFull({ error: input.error }))\n }\n\n if (isMissingDone(input.error) && input.outputStarted) {\n return Effect.succeed(\n StepOutcome.Continue({\n error: input.error,\n ...modelTurnResult(input.collected)\n })\n )\n }\n\n if (isRetryableLlm(input.error) && !input.outputStarted) {\n if (input.error.cause === 'invalid_response') {\n return Effect.succeed(StepOutcome.RecoverFull({ error: input.error }))\n }\n\n return Effect.succeed(StepOutcome.Retry({ error: input.error }))\n }\n\n if (isRetryableLlm(input.error) && input.outputStarted) {\n return Effect.succeed(\n StepOutcome.Continue({\n error: input.error,\n ...modelTurnResult(input.collected)\n })\n )\n }\n\n return Effect.fail(input.error)\n}\n\nexport const attemptModelTurn = <E2 = never, R2 = never>(\n config: ModelTurnConfig,\n options?: {\n readonly onEvent?: (event: AgentEvent) => Effect.Effect<void, E2, R2>\n readonly initialUsage?: AgentUsage\n readonly overflowCompactionAttempt?: number\n readonly compact?: (\n messages: ReadonlyArray<AgentMessage>\n ) => Effect.Effect<OverflowCompactionResult, E2, R2>\n }\n): Effect.Effect<\n ModelTurnOutcome,\n AgentLoopError | E2,\n ContextTransformer | LLMProvider | LoopConfig | R2\n> =>\n Effect.gen(function* () {\n const overflowCompactionAttempt = options?.overflowCompactionAttempt ?? 0\n\n if (!isOverflowCompactionAttemptCount(overflowCompactionAttempt)) {\n return yield* Effect.fail(invalidOverflowCompactionAttemptError())\n }\n\n const outcome = yield* collectModelTurnAttempt(runModelTurn(config), {\n onEvent: options?.onEvent,\n initialUsage: options?.initialUsage\n })\n\n return yield* Match.value(outcome).pipe(\n Match.tag('Collected', current => Effect.succeed(completedOutcome(current.collection))),\n Match.tag('SinkFailed', current => Effect.fail(current.error)),\n Match.tag('StreamFailed', current => {\n if (!isAgentLoopError(current.error)) {\n return Effect.fail(current.error)\n }\n\n return classifyModelTurnFailure({\n error: current.error,\n collected: {\n assistantMessage:\n current.collection.assistantMessage ?? current.collection.partialAssistantMessage,\n toolCalls: current.collection.toolCalls,\n usage: current.collection.usage,\n stopReason: current.collection.stopReason\n },\n outputStarted: current.collection.outputStarted,\n messages: config.messages,\n overflowCompactionAttempt,\n compact: options?.compact\n })\n }),\n Match.exhaustive\n )\n })\n\ntype AttemptToolBatchFoldState = {\n requests: ReadonlyArray<HitlRequest>\n usage: AgentUsage\n toolCalls: ModelTurnResult['toolCalls']\n}\n\nexport const attemptToolBatch = <E2 = never, R2 = never>(\n config: ToolBatchConfig,\n options?: {\n readonly onEvent?: (event: AgentEvent) => Effect.Effect<void, E2, R2>\n }\n): Effect.Effect<ToolBatchOutcome, AgentLoopError | E2, LoopConfig | ToolExecutor | R2> => {\n const onEvent = options?.onEvent\n\n return runToolBatch(config).pipe(\n Stream.runFoldEffect(\n (): AttemptToolBatchFoldState => ({\n requests: [],\n usage: config.usage ?? zeroAgentUsage,\n toolCalls: []\n }),\n (acc, event) => {\n const next = Predicate.isTagged(event, 'AgentAwaitingInput')\n ? { ...acc, requests: event.requests, usage: event.usage }\n : Predicate.isTagged(event, 'UsageUpdate')\n ? { ...acc, usage: addAgentUsage(acc.usage, event.usage) }\n : Predicate.isTagged(event, 'ToolExecutionCompleted') ||\n Predicate.isTagged(event, 'ToolExecutionAccepted')\n ? { ...acc, toolCalls: [...acc.toolCalls, event.call] }\n : acc\n\n return onEvent === undefined ? Effect.succeed(next) : onEvent(event).pipe(Effect.as(next))\n }\n ),\n Effect.map((result): ToolBatchOutcome => {\n if (result.requests.length === 0) {\n const needsContinuation = result.toolCalls.length > 0\n\n return StepOutcome.Completed({\n needsContinuation,\n assistantMessage: undefined,\n toolCalls: result.toolCalls,\n usage: result.usage,\n stopReason: needsContinuation ? 'tool_use' : 'stop'\n })\n }\n\n return StepOutcome.AwaitingInput({ requests: result.requests, usage: result.usage })\n })\n )\n}\n\nexport type HitlMatch =\n | { readonly _tag: 'Match'; readonly requestId: string }\n | { readonly _tag: 'Mismatch' }\n\nexport const HitlMatch = hitlMatch\n\nconst hitlResponseMatchesRequest = (response: HitlResponse, request: HitlRequest) =>\n Match.value(response).pipe(\n Match.tag(\n 'ToolApprovalResponse',\n current =>\n Predicate.isTagged(request, 'ToolApprovalRequest') &&\n current.requestId === request.requestId &&\n current.toolCallId === request.toolCallId\n ),\n Match.tag(\n 'QuestionResponse',\n current =>\n Predicate.isTagged(request, 'QuestionRequest') &&\n current.requestId === request.requestId &&\n current.toolCallId === request.toolCallId\n ),\n Match.tag(\n 'InputResponse',\n current =>\n Predicate.isTagged(request, 'InputRequest') &&\n current.requestId === request.requestId &&\n current.toolCallId === request.toolCallId\n ),\n Match.tag(\n 'InteractionResponse',\n current =>\n Predicate.isTagged(request, 'InteractionRequest') &&\n current.requestId === request.requestId &&\n current.toolCallId === request.toolCallId\n ),\n Match.exhaustive\n )\n\nexport const matchHitlResponse = (\n pending: ReadonlyArray<HitlRequest>,\n response: HitlResponse\n): HitlMatch => {\n const matched = pending.find(request => hitlResponseMatchesRequest(response, request))\n\n return matched === undefined\n ? HitlMatch.Mismatch()\n : HitlMatch.Match({ requestId: matched.requestId })\n}\n\nexport const resumeHitlIfMatched = <A, E, R>(input: {\n readonly pending: ReadonlyArray<HitlRequest>\n readonly response: HitlResponse\n readonly resume: (requestId: string) => Effect.Effect<A, E, R>\n}): Effect.Effect<A | Extract<HitlMatch, { readonly _tag: 'Mismatch' }>, E, R> => {\n const matched = matchHitlResponse(input.pending, input.response)\n\n return Match.value(matched).pipe(\n Match.tag('Mismatch', current => Effect.succeed(current)),\n Match.tag('Match', current => input.resume(current.requestId)),\n Match.exhaustive\n )\n}\n"],"mappings":";;;;;;AAsCA,MAAa,2BAA2BA;AAiCxC,MAAa,cAAcC;AAW3B,MAAM,oBAAoB,WACxB,YAAY,UAAU;CACpB,mBAAmB,OAAO,eAAe;CACzC,kBAAkB,OAAO;CACzB,WAAW,OAAO;CAClB,OAAO,OAAO;CACd,YAAY,OAAO;AACrB,CAAC;AAEH,MAAM,mBAAmB,YAA8C;CACrE,kBAAkB,OAAO;CACzB,WAAW,OAAO;CAClB,OAAO,OAAO;CACd,YAAY,OAAO;AACrB;AAEA,MAAM,8CACJ,IAAI,SAAS;CACX,OAAO;CACP,SAAS;CACT,WAAW;AACb,CAAC;AAEH,MAAM,oBAAoB,UAA4C;CACpE,IAAI,CAAC,UAAU,gBAAgB,KAAK,KAAK,EAAE,UAAU,QACnD,OAAO;CAGT,MAAM,MAAM,MAAM;CAElB,OACE,QAAQ,cACR,QAAQ,wBACR,QAAQ,eACR,QAAQ,2BACR,QAAQ;AAEZ;AAEA,MAAM,cAAc,UAClB,MAAM,MAAM,KAAK,EAAE,KACjB,MAAM,IAAI,YAAY,0BAAyB,YAAW,QAAQ,UAAU,kBAAkB,GAC9F,MAAM,aAAa,KAAK,CAC1B;AAEF,MAAM,iBAAiB,UACrB,MAAM,MAAM,KAAK,EAAE,KACjB,MAAM,IAAI,aAAY,YAAW,QAAQ,kBAAkB,cAAc,GACzE,MAAM,aAAa,KAAK,CAC1B;AAEF,MAAM,kBACJ,UAEA,UAAU,SAAS,OAAO,UAAU,KAAK,MAAM;AAEjD,MAAM,4BAAoC,UASsB;CAC9D,IAAI,WAAW,MAAM,KAAK,GAAG;EAC3B,IAAI,MAAM,YAAY,KAAA,GACpB,OAAO,OAAO,KAAK,MAAM,KAAK;EAGh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M,MAAM,OAAO,EAAE,KAC1B,MAAM,IAAI,aAAY,YAAW,OAAO,QAAQ,OAAO,CAAC,GACxD,MAAM,IAAI,UAAS,YAAW,MAAM,OAAO,QAAQ,SAAS,CAAC,GAC7D,MAAM,UACR;AACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yolk-sdk/harness",
|
|
3
|
-
"version": "0.1.0-canary.
|
|
3
|
+
"version": "0.1.0-canary.87",
|
|
4
4
|
"description": "Domain-free agent run lifecycle: coordinator, store, inbox, and pluggable drivers.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -79,7 +79,7 @@
|
|
|
79
79
|
},
|
|
80
80
|
"dependencies": {
|
|
81
81
|
"effect": "4.0.0-rc.115",
|
|
82
|
-
"@yolk-sdk/agent": "^0.1.0-canary.
|
|
82
|
+
"@yolk-sdk/agent": "^0.1.0-canary.87"
|
|
83
83
|
},
|
|
84
84
|
"scripts": {
|
|
85
85
|
"build": "tsdown",
|
package/src/outcome.ts
CHANGED
|
@@ -341,6 +341,13 @@ const hitlResponseMatchesRequest = (response: HitlResponse, request: HitlRequest
|
|
|
341
341
|
current.requestId === request.requestId &&
|
|
342
342
|
current.toolCallId === request.toolCallId
|
|
343
343
|
),
|
|
344
|
+
Match.tag(
|
|
345
|
+
'InteractionResponse',
|
|
346
|
+
current =>
|
|
347
|
+
Predicate.isTagged(request, 'InteractionRequest') &&
|
|
348
|
+
current.requestId === request.requestId &&
|
|
349
|
+
current.toolCallId === request.toolCallId
|
|
350
|
+
),
|
|
344
351
|
Match.exhaustive
|
|
345
352
|
)
|
|
346
353
|
|