Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions packages/fold-agent/test/TestHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ import {
ToolEvents,
ToolState,
type FoldTool,
type PlatformServices,
type ToolHandlerServices,
} from '@humanlayer/fold-core'
import { Effect, FileSystem, Layer, PlatformError, Ref, type Schema } from 'effect'

/** Run a tool handler effect with stubbed ambient services and recorded ToolEvents/InterruptNote feeds. */
export const makeAmbientServices = (): Effect.Effect<{
readonly layer: Layer.Layer<ToolHandlerServices>
readonly layer: Layer.Layer<ToolHandlerServices | PlatformServices>
readonly emitted: Effect.Effect<ReadonlyArray<typeof Schema.Json.Type>>
/** The most recent InterruptNote the handler recorded, or null. */
readonly interruptNote: Effect.Effect<string | null>
Expand Down Expand Up @@ -71,11 +72,13 @@ export const makeAmbientServices = (): Effect.Effect<{
/** Invoke one tool's handler through its init: the realized handler, still needing the ambient R. */
export const handlerOf =
(tool: FoldTool) =>
(params: unknown): Effect.Effect<unknown, unknown, ToolHandlerServices> =>
(params: unknown): Effect.Effect<unknown, unknown, ToolHandlerServices | FileSystem.FileSystem> =>
tool.init.pipe(Effect.flatMap((contribution) => contribution.handler(params)))

/** Run one handler with throwaway ambient services. */
export const runHandler = <A, E>(effect: Effect.Effect<A, E, ToolHandlerServices>): Effect.Effect<A, E> =>
export const runHandler = <A, E>(
effect: Effect.Effect<A, E, ToolHandlerServices | FileSystem.FileSystem>,
): Effect.Effect<A, E> =>
Effect.gen(function* () {
const ambient = yield* makeAmbientServices()
return yield* effect.pipe(Effect.provide(ambient.layer))
Expand Down
3 changes: 2 additions & 1 deletion packages/fold-codex/test/SessionModelPathTestHarness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
ToolEvents,
ToolState,
type FoldTool,
type PlatformServices,
type ToolHandlerServices,
type ToolResultLogEntry,
} from '@humanlayer/fold-core'
Expand Down Expand Up @@ -122,7 +123,7 @@ export const makeDeterministicColorBandsPng = (): Uint8Array => {
])
}

const toolHandlerTestLayer: Layer.Layer<ToolHandlerServices> = Layer.mergeAll(
const toolHandlerTestLayer: Layer.Layer<ToolHandlerServices | PlatformServices> = Layer.mergeAll(
NodeServices.layer,
Layer.succeed(ToolState, { get: () => Effect.succeed(null), set: () => Effect.void }),
Layer.succeed(ToolEvents, { emit: () => Effect.void }),
Expand Down
3 changes: 1 addition & 2 deletions packages/fold-core/examples/AnthropicAgent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*
* Run: ANTHROPIC_API_KEY=... bun packages/fold-core/examples/AnthropicAgent.ts
*/
import * as NodeFileSystem from '@effect/platform-node/NodeFileSystem'
import { Console, Effect, Schema } from 'effect'

import { anthropicModel, defineAgent, defineTool, startSession } from '../src/index'
Expand Down Expand Up @@ -42,7 +41,7 @@ const makeProgram = (apiKey: string) =>
yield* Console.log(`finished: ${finished.outcome}`)
yield* Console.log(`result: ${finished.resultText ?? '(no text)'}`)
yield* Console.log(`log: ${entries.map((entry) => entry._tag).join(' -> ')}`)
}).pipe(Effect.scoped, Effect.provide(NodeFileSystem.layer))
}).pipe(Effect.scoped)

if (apiKey === undefined || apiKey === '') {
console.error('Set ANTHROPIC_API_KEY to run this example.')
Expand Down
3 changes: 1 addition & 2 deletions packages/fold-core/examples/AutoCompactAgent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
*
* Run: OPENAI_API_KEY=... bun packages/fold-core/examples/AutoCompactAgent.ts
*/
import * as NodeFileSystem from '@effect/platform-node/NodeFileSystem'
import { Predicate, Console, Effect } from 'effect'

import { defineAgent, openaiModel, startSession, type CompactionLogEntry } from '../src/index'
Expand Down Expand Up @@ -78,7 +77,7 @@ const makeProgram = (key: string) =>
yield* Console.log('\nsend 3: the session keeps running on the compacted context...')
const third = yield* session.send('And what were we told about the dedupe window?')
yield* Console.log(` -> ${third.resultText ?? '(no text)'}`)
}).pipe(Effect.scoped, Effect.provide(NodeFileSystem.layer))
}).pipe(Effect.scoped)

if (apiKey === undefined || apiKey === '') {
console.error('Set OPENAI_API_KEY to run this example.')
Expand Down
3 changes: 1 addition & 2 deletions packages/fold-core/examples/ModelSwitch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
*
* Run: OPENAI_API_KEY=... ANTHROPIC_API_KEY=... bun packages/fold-core/examples/ModelSwitch.ts
*/
import * as NodeFileSystem from '@effect/platform-node/NodeFileSystem'
import { Console, Effect, Schema } from 'effect'

import { anthropicModel, defineAgent, defineTool, openaiModel, startSession } from '../src/index'
Expand Down Expand Up @@ -61,7 +60,7 @@ const makeProgram = (openAiKey: string, anthropicKey: string) =>

const entries = yield* session.entries
yield* Console.log(`log: ${entries.map((entry) => entry._tag).join(' -> ')}`)
}).pipe(Effect.scoped, Effect.provide(NodeFileSystem.layer))
}).pipe(Effect.scoped)

if (openAiKey === undefined || openAiKey === '' || anthropicKey === undefined || anthropicKey === '') {
console.error('Set OPENAI_API_KEY and ANTHROPIC_API_KEY to run this example.')
Expand Down
3 changes: 1 addition & 2 deletions packages/fold-core/examples/OpenaiAgent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*
* Run: OPENAI_API_KEY=... bun packages/fold-core/examples/OpenaiAgent.ts
*/
import * as NodeFileSystem from '@effect/platform-node/NodeFileSystem'
import { Console, Effect, Schema } from 'effect'

import { defineAgent, defineTool, openaiModel, startSession } from '../src/index'
Expand Down Expand Up @@ -41,7 +40,7 @@ const makeProgram = (apiKey: string) =>
yield* Console.log(`finished: ${finished.outcome}`)
yield* Console.log(`result: ${finished.resultText ?? '(no text)'}`)
yield* Console.log(`log: ${entries.map((entry) => entry._tag).join(' -> ')}`)
}).pipe(Effect.scoped, Effect.provide(NodeFileSystem.layer))
}).pipe(Effect.scoped)

if (apiKey === undefined || apiKey === '') {
console.error('Set OPENAI_API_KEY to run this example.')
Expand Down
3 changes: 1 addition & 2 deletions packages/fold-core/examples/SkillsAgent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
*
* Run: ANTHROPIC_API_KEY=... bun packages/fold-core/examples/SkillsAgent.ts
*/
import * as NodeFileSystem from '@effect/platform-node/NodeFileSystem'
import { Console, Effect } from 'effect'

import { anthropicModel, defineAgent, skillsFromData, skillTool, startSession } from '../src/index'
Expand Down Expand Up @@ -51,7 +50,7 @@ const makeProgram = (apiKey: string) =>
yield* Console.log(`finished: ${finished.outcome}`)
yield* Console.log(`result:\n${finished.resultText ?? '(no text)'}`)
yield* Console.log(`log: ${entries.map((entry) => entry._tag).join(' -> ')}`)
}).pipe(Effect.scoped, Effect.provide(NodeFileSystem.layer))
}).pipe(Effect.scoped)

if (apiKey === undefined || apiKey === '') {
console.error('Set ANTHROPIC_API_KEY to run this example.')
Expand Down
3 changes: 1 addition & 2 deletions packages/fold-core/src/Api/Provisioning.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import { AnthropicClient, AnthropicLanguageModel } from '@humanlayer/effect-ai-anthropic'
import { OpenAiClient, OpenAiLanguageModel } from '@humanlayer/effect-ai-openai'
import { Context, Effect, Layer, Match, Stream } from 'effect'
import type { FileSystem, Scope } from 'effect'
import type { Scope } from 'effect'
import { LanguageModel, Toolkit } from 'effect/unstable/ai'
import type { Tool } from 'effect/unstable/ai'
import { FetchHttpClient, HttpClient } from 'effect/unstable/http'
Expand Down Expand Up @@ -95,7 +95,6 @@ export type SessionProvisioningServices =
| ToolEventSink
| Subagents
| SessionControls
| FileSystem.FileSystem

/** Lower a model descriptor to the LanguageModel layer for its provider connection. */
export const languageModelLayerFor = (model: FoldModel): Layer.Layer<LanguageModel.LanguageModel> => {
Expand Down
Loading
Loading