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
40 changes: 10 additions & 30 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"@pulumi/pulumi": "3.231.0",
"ai": "6.0.199",
"commander": "14.0.3",
"effect": "4.0.0-beta.107",
"effect": "4.0.0",
"minimatch": "10.1.1",
"typescript": "5.9.3",
"zod": "4.5.4"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export function convertPromptMessages(prompt: LanguageModelV3Prompt): {
for (const message of prompt) {
switch (message.role) {
case 'system': {
systemParts.push(SystemPart.make(message.content))
systemParts.push(SystemPart.text(message.content))
break
}

Expand Down
4 changes: 2 additions & 2 deletions packages/opencode-llm-vendor/src/protocols/shared.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Buffer } from 'node:buffer'
import { Effect, Schema, Stream } from 'effect'
import * as Sse from 'effect/encoding/Sse'
import { Headers, HttpClientRequest } from 'effect/http'
import * as Option from 'effect/Option'
import * as Sse from 'effect/unstable/encoding/Sse'
import { Headers, HttpClientRequest } from 'effect/unstable/http'
import { type Interface as DiagnosticsInterface, LLMDiagnostics, noopDiagnostics } from '../route/diagnostics'
import {
type ContentPart,
Expand Down
2 changes: 1 addition & 1 deletion packages/opencode-llm-vendor/src/route/auth.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @ts-nocheck — vendored from opencode, tested upstream under different tsconfig
import { Config, Effect, Redacted } from 'effect'
import { Headers } from 'effect/http'
import * as Option from 'effect/Option'
import { Headers } from 'effect/unstable/http'
import { AuthenticationReason, InvalidRequestReason, LLMError, type LLMRequest } from '../schema'
import { type Interface as DiagnosticsInterface, LLMDiagnostics, noopDiagnostics } from './diagnostics'

Expand Down
4 changes: 2 additions & 2 deletions packages/opencode-llm-vendor/src/route/executor.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// @ts-nocheck — vendored from opencode, tested upstream under different tsconfig
import { Cause, Context, Effect, Layer, Random } from 'effect'
import * as Option from 'effect/Option'
import {
FetchHttpClient,
Headers,
HttpClient,
HttpClientError,
type HttpClientRequest,
type HttpClientResponse,
} from 'effect/unstable/http'
} from 'effect/http'
import * as Option from 'effect/Option'
import {
AuthenticationReason,
ContentPolicyReason,
Expand Down
2 changes: 1 addition & 1 deletion packages/opencode-llm-vendor/src/route/transport/http.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Effect, Stream } from 'effect'
import { Headers, type HttpClientRequest } from 'effect/unstable/http'
import { Headers, type HttpClientRequest } from 'effect/http'
import * as ProviderShared from '../../protocols/shared'
import type { LLMRequest } from '../../schema'
import { LLMError, mergeJsonRecords, TransportReason } from '../../schema'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @ts-nocheck — vendored from opencode, tested upstream under different tsconfig
import { Cause, Context, Duration, Effect, Layer, Queue, Schedule, Stream } from 'effect'
import type { Headers } from 'effect/http'
import * as Option from 'effect/Option'
import type { Headers } from 'effect/unstable/http'
import { LLMError, TransportReason } from '../../schema'
import { LLMDiagnostics, llmErrorMetadata, noopDiagnostics } from '../diagnostics'
import * as HttpTransport from './http'
Expand Down
39 changes: 17 additions & 22 deletions packages/opencode-llm-vendor/src/schema/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ const systemPartSchema = Schema.Struct({
}).annotate({ identifier: 'LLM.SystemPart' })
export type SystemPart = Schema.Schema.Type<typeof systemPartSchema>

const makeSystemPart = (text: string): SystemPart => ({ type: 'text', text })
const systemText = (text: string): SystemPart => ({ type: 'text', text })

export const SystemPart = Object.assign(systemPartSchema, {
make: makeSystemPart,
text: systemText,
content: (input?: string | SystemPart | ReadonlyArray<SystemPart>) => {
if (input === undefined) return []
return typeof input === 'string' ? [makeSystemPart(input)] : Array.isArray(input) ? [...input] : [input]
return typeof input === 'string' ? [systemText(input)] : Array.isArray(input) ? [...input] : [input]
},
})

Expand Down Expand Up @@ -86,7 +86,7 @@ export const ToolResultValue = Object.assign(
]).annotate({ identifier: 'LLM.ToolResult' }),
{
is: isToolResultValue,
make: (value: unknown, type: ToolResultValue['type'] = 'json'): ToolResultValue => {
from: (value: unknown, type: ToolResultValue['type'] = 'json'): ToolResultValue => {
if (isToolResultValue(value)) return value
if (type === 'content') return { type, value: Array.isArray(value) ? value : [] }
return { type, value }
Expand All @@ -95,20 +95,15 @@ export const ToolResultValue = Object.assign(
)
export type ToolResultValue = Schema.Schema.Type<typeof ToolResultValue>

export const ToolCallPart = Object.assign(
Schema.Struct({
type: Schema.Literal('tool-call'),
id: Schema.String,
name: Schema.String,
input: Schema.Unknown,
providerExecuted: Schema.optional(Schema.Boolean),
metadata: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),
providerMetadata: Schema.optional(ProviderMetadata),
}).annotate({ identifier: 'LLM.Content.ToolCall' }),
{
make: (input: Omit<ToolCallPart, 'type'>): ToolCallPart => ({ type: 'tool-call', ...input }),
},
)
export const ToolCallPart = Schema.Struct({
type: Schema.tag('tool-call'),
id: Schema.String,
name: Schema.String,
input: Schema.Unknown,
providerExecuted: Schema.optional(Schema.Boolean),
metadata: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),
providerMetadata: Schema.optional(ProviderMetadata),
}).annotate({ identifier: 'LLM.Content.ToolCall' })
export type ToolCallPart = Schema.Schema.Type<typeof ToolCallPart>

export const ToolResultPart = Object.assign(
Expand All @@ -123,7 +118,7 @@ export const ToolResultPart = Object.assign(
providerMetadata: Schema.optional(ProviderMetadata),
}).annotate({ identifier: 'LLM.Content.ToolResult' }),
{
make: (
from: (
input: Omit<ToolResultPart, 'type' | 'result'> & {
readonly result: unknown
readonly resultType?: ToolResultValue['type']
Expand All @@ -132,7 +127,7 @@ export const ToolResultPart = Object.assign(
type: 'tool-result',
id: input.id,
name: input.name,
result: ToolResultValue.make(input.result, input.resultType),
result: ToolResultValue.from(input.result, input.resultType),
providerExecuted: input.providerExecuted,
cache: input.cache,
metadata: input.metadata,
Expand Down Expand Up @@ -184,8 +179,8 @@ export namespace Message {

export const assistant = (content: ContentInput) => make({ role: 'assistant', content })

export const tool = (result: ToolResultPart | Parameters<typeof ToolResultPart.make>[0]) =>
make({ role: 'tool', content: ['type' in result ? result : ToolResultPart.make(result)] })
export const tool = (result: ToolResultPart | Parameters<typeof ToolResultPart.from>[0]) =>
make({ role: 'tool', content: ['type' in result ? result : ToolResultPart.from(result)] })
}

export class ToolDefinition extends Schema.Class<ToolDefinition>('LLM.ToolDefinition')({
Expand Down
2 changes: 1 addition & 1 deletion packages/opencode-llm-vendor/src/tool-runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ const accumulate = (state: StepState, event: LLMEvent) => {
}
if (event.type === 'tool-result' && event.providerExecuted) {
state.assistantContent.push(
ToolResultPart.make({
ToolResultPart.from({
id: event.id,
name: event.name,
result: event.result,
Expand Down
Loading