@ai-sdk/harness-cline 0.0.0 → 1.0.1
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/CHANGELOG.md +23 -0
- package/LICENSE +13 -0
- package/README.md +56 -3
- package/dist/index.d.ts +127 -0
- package/dist/index.js +1655 -0
- package/dist/index.js.map +1 -0
- package/package.json +63 -11
- package/src/cline-auth.ts +40 -0
- package/src/cline-harness.ts +197 -0
- package/src/cline-mcp.ts +153 -0
- package/src/cline-remote-ops.ts +243 -0
- package/src/cline-resume-state.ts +139 -0
- package/src/cline-session.ts +915 -0
- package/src/cline-skills.ts +59 -0
- package/src/cline-tools.ts +381 -0
- package/src/cline-translate.ts +261 -0
- package/src/cline-utils.ts +151 -0
- package/src/index.ts +13 -0
- package/src/version.ts +6 -0
- package/index.js +0 -1
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
JSONValue,
|
|
3
|
+
LanguageModelV4FinishReason,
|
|
4
|
+
LanguageModelV4Usage,
|
|
5
|
+
} from '@ai-sdk/provider';
|
|
6
|
+
import {
|
|
7
|
+
HarnessCapabilityUnsupportedError,
|
|
8
|
+
type HarnessV1Prompt,
|
|
9
|
+
} from '@ai-sdk/harness';
|
|
10
|
+
import { secureJsonParse } from '@ai-sdk/provider-utils';
|
|
11
|
+
import type { AgentMessage, AgentUsage } from '@cline/agents';
|
|
12
|
+
|
|
13
|
+
const HARNESS_ID = 'cline';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Extract a single user text string from a `HarnessV1Prompt`. The Cline
|
|
17
|
+
* runtime's `run`/`continue` accept a plain string; multimodal user content
|
|
18
|
+
* is not supported in this foundational version.
|
|
19
|
+
*/
|
|
20
|
+
export function extractUserText(prompt: HarnessV1Prompt): string {
|
|
21
|
+
if (typeof prompt === 'string') {
|
|
22
|
+
return prompt;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const { content } = prompt;
|
|
26
|
+
if (typeof content === 'string') {
|
|
27
|
+
return content;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const parts: string[] = [];
|
|
31
|
+
for (const part of content) {
|
|
32
|
+
if (part.type !== 'text') {
|
|
33
|
+
throw new HarnessCapabilityUnsupportedError({
|
|
34
|
+
message: `cline: only text user-message parts are supported; got '${part.type}'.`,
|
|
35
|
+
harnessId: HARNESS_ID,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
parts.push(part.text);
|
|
39
|
+
}
|
|
40
|
+
return parts.join('\n\n');
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function getErrorText(error: unknown): string {
|
|
44
|
+
return error instanceof Error ? error.message : String(error);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Coerce an arbitrary tool output into a JSON-safe value for a `tool-result`
|
|
49
|
+
* stream part. Strings and JSON-serializable objects pass through; anything
|
|
50
|
+
* that can't survive `JSON.stringify` round-tripping (functions, cycles) is
|
|
51
|
+
* stringified. `undefined` becomes `null` — the runtime schema deliberately
|
|
52
|
+
* accepts `null` for tools with no output.
|
|
53
|
+
*/
|
|
54
|
+
export function toToolResultValue(output: unknown): NonNullable<JSONValue> {
|
|
55
|
+
if (output === undefined || output === null) {
|
|
56
|
+
return null as unknown as NonNullable<JSONValue>;
|
|
57
|
+
}
|
|
58
|
+
if (typeof output === 'string') {
|
|
59
|
+
return output;
|
|
60
|
+
}
|
|
61
|
+
try {
|
|
62
|
+
const serialized = JSON.stringify(output);
|
|
63
|
+
return serialized === undefined
|
|
64
|
+
? String(output)
|
|
65
|
+
: (secureJsonParse(serialized) as NonNullable<JSONValue>);
|
|
66
|
+
} catch {
|
|
67
|
+
return String(output);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Map the Cline model-level finish reason (`AgentModelFinishReason`) onto the
|
|
73
|
+
* V4 unified finish-reason vocabulary. Used for `finish-step` parts.
|
|
74
|
+
*/
|
|
75
|
+
export function mapModelFinishReason(
|
|
76
|
+
reason: string,
|
|
77
|
+
): LanguageModelV4FinishReason {
|
|
78
|
+
switch (reason) {
|
|
79
|
+
case 'stop':
|
|
80
|
+
return { unified: 'stop', raw: reason };
|
|
81
|
+
case 'tool-calls':
|
|
82
|
+
return { unified: 'tool-calls', raw: reason };
|
|
83
|
+
case 'max-tokens':
|
|
84
|
+
return { unified: 'length', raw: reason };
|
|
85
|
+
case 'error':
|
|
86
|
+
return { unified: 'error', raw: reason };
|
|
87
|
+
default:
|
|
88
|
+
return { unified: 'other', raw: reason };
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Map a completed run's status onto the V4 unified finish reason. Used for
|
|
94
|
+
* the terminal `finish` part.
|
|
95
|
+
*/
|
|
96
|
+
export function mapRunFinishReason(
|
|
97
|
+
status: 'completed' | 'aborted' | 'failed',
|
|
98
|
+
): LanguageModelV4FinishReason {
|
|
99
|
+
switch (status) {
|
|
100
|
+
case 'completed':
|
|
101
|
+
return { unified: 'stop', raw: status };
|
|
102
|
+
case 'aborted':
|
|
103
|
+
return { unified: 'other', raw: status };
|
|
104
|
+
case 'failed':
|
|
105
|
+
return { unified: 'error', raw: status };
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Convert the Cline runtime's cumulative `AgentUsage` into the V4 usage shape.
|
|
111
|
+
*/
|
|
112
|
+
export function usageFromAgentUsage(usage: AgentUsage): LanguageModelV4Usage {
|
|
113
|
+
return {
|
|
114
|
+
inputTokens: {
|
|
115
|
+
total: usage.inputTokens,
|
|
116
|
+
noCache: undefined,
|
|
117
|
+
cacheRead: usage.cacheReadTokens,
|
|
118
|
+
cacheWrite: usage.cacheWriteTokens,
|
|
119
|
+
},
|
|
120
|
+
outputTokens: {
|
|
121
|
+
total: usage.outputTokens,
|
|
122
|
+
text: undefined,
|
|
123
|
+
reasoning: usage.reasoningTokenCount,
|
|
124
|
+
},
|
|
125
|
+
...(usage.totalCost !== undefined
|
|
126
|
+
? { raw: { totalCost: usage.totalCost } }
|
|
127
|
+
: {}),
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Convert a single assistant message's per-call metrics into the V4 usage
|
|
133
|
+
* shape. Metrics may be absent; all fields stay optional in that case.
|
|
134
|
+
*/
|
|
135
|
+
export function usageFromMessageMetrics(
|
|
136
|
+
metrics: AgentMessage['metrics'],
|
|
137
|
+
): LanguageModelV4Usage {
|
|
138
|
+
return {
|
|
139
|
+
inputTokens: {
|
|
140
|
+
total: metrics?.inputTokens,
|
|
141
|
+
noCache: undefined,
|
|
142
|
+
cacheRead: metrics?.cacheReadTokens,
|
|
143
|
+
cacheWrite: metrics?.cacheWriteTokens,
|
|
144
|
+
},
|
|
145
|
+
outputTokens: {
|
|
146
|
+
total: metrics?.outputTokens,
|
|
147
|
+
text: undefined,
|
|
148
|
+
reasoning: metrics?.reasoningTokenCount,
|
|
149
|
+
},
|
|
150
|
+
};
|
|
151
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { createCline } from './cline-harness';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Default `cline` harness instance with no overrides — suitable for the
|
|
5
|
+
* common case where the Cline SDK's defaults are fine. Equivalent to
|
|
6
|
+
* `createCline()`.
|
|
7
|
+
*/
|
|
8
|
+
export const cline = createCline();
|
|
9
|
+
|
|
10
|
+
export { createCline } from './cline-harness';
|
|
11
|
+
export { VERSION } from './version';
|
|
12
|
+
export type { ClineHarnessSettings } from './cline-harness';
|
|
13
|
+
export type { ClineAuthenticationMode, ClineAuthOptions } from './cline-auth';
|
package/src/version.ts
ADDED
package/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|