pi-commandcode-provider 0.1.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/LICENSE +21 -0
- package/README.md +110 -0
- package/index.ts +197 -0
- package/package.json +54 -0
- package/src/auth-server.ts +214 -0
- package/src/converters.ts +276 -0
- package/src/core.ts +458 -0
- package/src/oauth.ts +167 -0
- package/src/types.ts +156 -0
package/src/types.ts
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
export type StopReason = "stop" | "length" | "toolUse"
|
|
2
|
+
export type ErrorReason = "error" | "aborted"
|
|
3
|
+
export type TerminalReason = StopReason | ErrorReason
|
|
4
|
+
|
|
5
|
+
export interface UsageCost {
|
|
6
|
+
input: number
|
|
7
|
+
output: number
|
|
8
|
+
cacheRead: number
|
|
9
|
+
cacheWrite: number
|
|
10
|
+
total: number
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface Usage {
|
|
14
|
+
input: number
|
|
15
|
+
output: number
|
|
16
|
+
cacheRead: number
|
|
17
|
+
cacheWrite: number
|
|
18
|
+
totalTokens: number
|
|
19
|
+
cost: UsageCost
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface TextContent {
|
|
23
|
+
type: "text"
|
|
24
|
+
text: string
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface ThinkingContent {
|
|
28
|
+
type: "thinking"
|
|
29
|
+
thinking: string
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface ToolCallContent {
|
|
33
|
+
type: "toolCall"
|
|
34
|
+
id: string
|
|
35
|
+
name: string
|
|
36
|
+
arguments: Record<string, unknown>
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export type AssistantContent = TextContent | ThinkingContent | ToolCallContent
|
|
40
|
+
|
|
41
|
+
export interface AssistantMessageLike {
|
|
42
|
+
role: "assistant"
|
|
43
|
+
content: AssistantContent[]
|
|
44
|
+
api: unknown
|
|
45
|
+
provider: string
|
|
46
|
+
model: string
|
|
47
|
+
usage: Usage
|
|
48
|
+
stopReason: TerminalReason
|
|
49
|
+
errorMessage?: string
|
|
50
|
+
timestamp: number
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export interface ModelLike {
|
|
54
|
+
id: string
|
|
55
|
+
api: unknown
|
|
56
|
+
provider: string
|
|
57
|
+
maxTokens: number
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export interface MessageLike {
|
|
61
|
+
role: string
|
|
62
|
+
content?: unknown
|
|
63
|
+
toolCallId?: string
|
|
64
|
+
toolName?: string
|
|
65
|
+
isError?: boolean
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export interface ToolLike {
|
|
69
|
+
name: string
|
|
70
|
+
description?: string
|
|
71
|
+
parameters?: unknown
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export interface ContextLike {
|
|
75
|
+
systemPrompt?: string
|
|
76
|
+
messages?: readonly MessageLike[]
|
|
77
|
+
tools?: readonly ToolLike[]
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export interface ProviderResponseInfo {
|
|
81
|
+
status: number
|
|
82
|
+
headers: Record<string, string>
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export interface StreamOptions {
|
|
86
|
+
apiKey?: string
|
|
87
|
+
signal?: AbortSignal
|
|
88
|
+
headers?: Record<string, string>
|
|
89
|
+
maxTokens?: number
|
|
90
|
+
onPayload?: (payload: unknown, model: ModelLike) => unknown | Promise<unknown>
|
|
91
|
+
onResponse?: (response: ProviderResponseInfo, model: ModelLike) => void | Promise<void>
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export type AssistantMessageEvent =
|
|
95
|
+
| { type: "start"; partial: AssistantMessageLike }
|
|
96
|
+
| { type: "text_start"; contentIndex: number; partial: AssistantMessageLike }
|
|
97
|
+
| {
|
|
98
|
+
type: "text_delta"
|
|
99
|
+
contentIndex: number
|
|
100
|
+
delta: string
|
|
101
|
+
partial: AssistantMessageLike
|
|
102
|
+
}
|
|
103
|
+
| {
|
|
104
|
+
type: "text_end"
|
|
105
|
+
contentIndex: number
|
|
106
|
+
content: string
|
|
107
|
+
partial: AssistantMessageLike
|
|
108
|
+
}
|
|
109
|
+
| {
|
|
110
|
+
type: "thinking_start"
|
|
111
|
+
contentIndex: number
|
|
112
|
+
partial: AssistantMessageLike
|
|
113
|
+
}
|
|
114
|
+
| {
|
|
115
|
+
type: "thinking_delta"
|
|
116
|
+
contentIndex: number
|
|
117
|
+
delta: string
|
|
118
|
+
partial: AssistantMessageLike
|
|
119
|
+
}
|
|
120
|
+
| {
|
|
121
|
+
type: "thinking_end"
|
|
122
|
+
contentIndex: number
|
|
123
|
+
content: string
|
|
124
|
+
partial: AssistantMessageLike
|
|
125
|
+
}
|
|
126
|
+
| {
|
|
127
|
+
type: "toolcall_start"
|
|
128
|
+
contentIndex: number
|
|
129
|
+
partial: AssistantMessageLike
|
|
130
|
+
}
|
|
131
|
+
| {
|
|
132
|
+
type: "toolcall_end"
|
|
133
|
+
contentIndex: number
|
|
134
|
+
toolCall: ToolCallContent
|
|
135
|
+
partial: AssistantMessageLike
|
|
136
|
+
}
|
|
137
|
+
| { type: "done"; reason: StopReason; message: AssistantMessageLike }
|
|
138
|
+
| { type: "error"; reason: ErrorReason; error: AssistantMessageLike }
|
|
139
|
+
|
|
140
|
+
export interface AssistantMessageEventStreamLike extends AsyncIterable<AssistantMessageEvent> {
|
|
141
|
+
push(event: AssistantMessageEvent): void
|
|
142
|
+
end(): void
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export interface CoreDependencies {
|
|
146
|
+
createStream: () => AssistantMessageEventStreamLike
|
|
147
|
+
calculateCost: (model: ModelLike, usage: Usage) => void
|
|
148
|
+
apiBase?: string
|
|
149
|
+
fetchImpl?: typeof fetch
|
|
150
|
+
authPaths?: readonly string[]
|
|
151
|
+
env?: NodeJS.ProcessEnv
|
|
152
|
+
cwd?: () => string
|
|
153
|
+
now?: () => number
|
|
154
|
+
uuid?: () => string
|
|
155
|
+
homeDir?: () => string
|
|
156
|
+
}
|