@love-moon/ai-sdk 0.2.38 → 0.2.40
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/client.d.ts +4 -1
- package/dist/client.js +14 -2
- package/dist/external-provider-registry.js +38 -2
- package/dist/providers/claude-agent-sdk-session.d.ts +4 -2
- package/dist/providers/claude-agent-sdk-session.js +25 -5
- package/dist/providers/codex-app-server-session.d.ts +3 -2
- package/dist/providers/codex-app-server-session.js +22 -4
- package/dist/providers/codex-exec-session.d.ts +116 -0
- package/dist/providers/codex-exec-session.js +583 -0
- package/dist/providers/copilot-sdk-session.d.ts +193 -0
- package/dist/providers/copilot-sdk-session.js +1463 -0
- package/dist/providers/kimi-cli-session.d.ts +3 -2
- package/dist/providers/kimi-cli-session.js +17 -3
- package/dist/providers/kimi-print-session.d.ts +125 -0
- package/dist/providers/kimi-print-session.js +633 -0
- package/dist/providers/opencode-sdk-session.d.ts +3 -2
- package/dist/providers/opencode-sdk-session.js +7 -2
- package/dist/session-factory.d.ts +7 -1
- package/dist/session-factory.js +48 -6
- package/dist/shared.d.ts +1 -0
- package/dist/shared.js +39 -20
- package/dist/transports/codex-app-server-transport.d.ts +1 -0
- package/dist/transports/codex-app-server-transport.js +10 -5
- package/dist/worker.js +39 -32
- package/package.json +3 -2
|
@@ -143,10 +143,11 @@ export class KimiCliSession extends EventEmitter<[never]> {
|
|
|
143
143
|
handleWireEvent(type: any, payload: any): Promise<void>;
|
|
144
144
|
handleTransportFailure(error: any): void;
|
|
145
145
|
handleTransportExit(payload: any): void;
|
|
146
|
-
interruptCurrentTurn(): Promise<
|
|
147
|
-
runTurn(promptText: any, { useInitialImages, onProgress }?: {
|
|
146
|
+
interruptCurrentTurn(): Promise<boolean>;
|
|
147
|
+
runTurn(promptText: any, { useInitialImages, onProgress, jsonSchema }?: {
|
|
148
148
|
useInitialImages?: boolean | undefined;
|
|
149
149
|
onProgress?: null | undefined;
|
|
150
|
+
jsonSchema?: null | undefined;
|
|
150
151
|
}): Promise<{
|
|
151
152
|
text: string;
|
|
152
153
|
usage: null;
|
|
@@ -106,6 +106,15 @@ function buildEmptyTurnResult() {
|
|
|
106
106
|
events: [],
|
|
107
107
|
};
|
|
108
108
|
}
|
|
109
|
+
function injectJsonSchemaPrompt(promptText, jsonSchema) {
|
|
110
|
+
const schemaText = typeof jsonSchema === "string" ? jsonSchema : JSON.stringify(jsonSchema, null, 2);
|
|
111
|
+
return `You must respond with valid JSON that strictly conforms to the following JSON Schema. Do not include any markdown formatting or explanation outside the JSON object.
|
|
112
|
+
|
|
113
|
+
JSON Schema:
|
|
114
|
+
${schemaText}
|
|
115
|
+
|
|
116
|
+
${promptText}`;
|
|
117
|
+
}
|
|
109
118
|
export class KimiCliSession extends EventEmitter {
|
|
110
119
|
constructor(backend, options = {}) {
|
|
111
120
|
super();
|
|
@@ -812,20 +821,25 @@ export class KimiCliSession extends EventEmitter {
|
|
|
812
821
|
}
|
|
813
822
|
async interruptCurrentTurn() {
|
|
814
823
|
if (!this.currentTurn) {
|
|
815
|
-
return;
|
|
824
|
+
return false;
|
|
816
825
|
}
|
|
817
826
|
try {
|
|
818
827
|
await this.transport.request("cancel", {});
|
|
828
|
+
return true;
|
|
819
829
|
}
|
|
820
830
|
catch {
|
|
821
831
|
// best effort
|
|
822
832
|
}
|
|
833
|
+
return false;
|
|
823
834
|
}
|
|
824
|
-
async runTurn(promptText, { useInitialImages = false, onProgress = null } = {}) {
|
|
835
|
+
async runTurn(promptText, { useInitialImages = false, onProgress = null, jsonSchema = null } = {}) {
|
|
825
836
|
if (this.closeRequested || this.closed) {
|
|
826
837
|
throw this.createSessionClosedError();
|
|
827
838
|
}
|
|
828
|
-
|
|
839
|
+
let effectivePrompt = this.buildPrompt(promptText, { useInitialImages });
|
|
840
|
+
if (jsonSchema && typeof jsonSchema === "object" && effectivePrompt) {
|
|
841
|
+
effectivePrompt = injectJsonSchemaPrompt(effectivePrompt, jsonSchema);
|
|
842
|
+
}
|
|
829
843
|
if (!effectivePrompt) {
|
|
830
844
|
return buildEmptyTurnResult();
|
|
831
845
|
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
export class KimiPrintSession extends EventEmitter<[never]> {
|
|
2
|
+
constructor(backend: any, options?: {});
|
|
3
|
+
backend: string;
|
|
4
|
+
options: {};
|
|
5
|
+
logger: any;
|
|
6
|
+
cwd: any;
|
|
7
|
+
resumeSessionId: any;
|
|
8
|
+
sessionId: any;
|
|
9
|
+
sessionInfo: {
|
|
10
|
+
backend: string;
|
|
11
|
+
sessionId: any;
|
|
12
|
+
model: any;
|
|
13
|
+
};
|
|
14
|
+
history: any[];
|
|
15
|
+
pendingHistorySeed: boolean;
|
|
16
|
+
closeRequested: boolean;
|
|
17
|
+
closed: boolean;
|
|
18
|
+
currentTurn: {
|
|
19
|
+
child: null;
|
|
20
|
+
fullText: string;
|
|
21
|
+
items: never[];
|
|
22
|
+
stderrTail: never[];
|
|
23
|
+
settled: boolean;
|
|
24
|
+
} | null;
|
|
25
|
+
currentTurnStatus: any;
|
|
26
|
+
sessionAnnounced: boolean;
|
|
27
|
+
sessionMessageHandler: any;
|
|
28
|
+
workingStatusHandler: any;
|
|
29
|
+
activeReplyTarget: string;
|
|
30
|
+
lastReplyTarget: string;
|
|
31
|
+
turnDeadlineMs: any;
|
|
32
|
+
env: any;
|
|
33
|
+
command: string;
|
|
34
|
+
baseArgs: string[];
|
|
35
|
+
writeLog(message: any): void;
|
|
36
|
+
trace(message: any): void;
|
|
37
|
+
get threadId(): any;
|
|
38
|
+
get threadOptions(): {
|
|
39
|
+
model: any;
|
|
40
|
+
};
|
|
41
|
+
buildManualResumeCommand(): string;
|
|
42
|
+
getSnapshot(): {
|
|
43
|
+
backend: string;
|
|
44
|
+
provider: string;
|
|
45
|
+
cwd: any;
|
|
46
|
+
sessionId: any;
|
|
47
|
+
sessionInfo: {
|
|
48
|
+
backend: string;
|
|
49
|
+
sessionId: any;
|
|
50
|
+
model: any;
|
|
51
|
+
} | null;
|
|
52
|
+
useSessionFileReplyStream: boolean;
|
|
53
|
+
resumeReady: boolean;
|
|
54
|
+
manualResume: {
|
|
55
|
+
ready: boolean;
|
|
56
|
+
command: string;
|
|
57
|
+
} | null;
|
|
58
|
+
currentTurnStatus: any;
|
|
59
|
+
pid: any;
|
|
60
|
+
};
|
|
61
|
+
getSessionInfo(): {
|
|
62
|
+
backend: string;
|
|
63
|
+
sessionId: any;
|
|
64
|
+
model: any;
|
|
65
|
+
} | null;
|
|
66
|
+
getCurrentTurnStatus(): any;
|
|
67
|
+
ensureSessionInfo(): Promise<{
|
|
68
|
+
backend: string;
|
|
69
|
+
sessionId: any;
|
|
70
|
+
model: any;
|
|
71
|
+
} | null>;
|
|
72
|
+
getSessionUsageSummary(): Promise<{
|
|
73
|
+
sessionId: any;
|
|
74
|
+
sessionFilePath: undefined;
|
|
75
|
+
tokenUsagePercent: undefined;
|
|
76
|
+
contextUsagePercent: undefined;
|
|
77
|
+
tokenUsage: null;
|
|
78
|
+
rateLimits: null;
|
|
79
|
+
manualResume: {
|
|
80
|
+
ready: boolean;
|
|
81
|
+
command: string;
|
|
82
|
+
} | null;
|
|
83
|
+
}>;
|
|
84
|
+
usesSessionFileReplyStream(): boolean;
|
|
85
|
+
setSessionMessageHandler(handler: any): void;
|
|
86
|
+
setWorkingStatusHandler(handler: any): void;
|
|
87
|
+
setSessionReplyTarget(replyTo: any): void;
|
|
88
|
+
getCurrentReplyTarget(): string | undefined;
|
|
89
|
+
announceSession(): void;
|
|
90
|
+
createSessionClosedError(): Error;
|
|
91
|
+
updateCurrentTurnStatus(payload: any): void;
|
|
92
|
+
emitWorkingStatus(payload: any, onProgress?: null): Promise<any>;
|
|
93
|
+
emitAssistantMessage(text: any): Promise<void>;
|
|
94
|
+
buildPrompt(promptText: any): string;
|
|
95
|
+
buildPrintArgs(): string[];
|
|
96
|
+
buildUserMessage(promptText: any, { useInitialImages }?: {
|
|
97
|
+
useInitialImages?: boolean | undefined;
|
|
98
|
+
}): {
|
|
99
|
+
role: string;
|
|
100
|
+
content: any;
|
|
101
|
+
};
|
|
102
|
+
maybeEmitAuthRequired(stderrTail: any): void;
|
|
103
|
+
runTurn(promptText: any, { useInitialImages, onProgress, jsonSchema }?: {
|
|
104
|
+
useInitialImages?: boolean | undefined;
|
|
105
|
+
onProgress?: null | undefined;
|
|
106
|
+
jsonSchema?: null | undefined;
|
|
107
|
+
}): Promise<{
|
|
108
|
+
text: string;
|
|
109
|
+
usage: null;
|
|
110
|
+
items: never[];
|
|
111
|
+
events: never[];
|
|
112
|
+
} | {
|
|
113
|
+
text: any;
|
|
114
|
+
usage: null;
|
|
115
|
+
items: any;
|
|
116
|
+
events: any;
|
|
117
|
+
provider: string;
|
|
118
|
+
metadata: {
|
|
119
|
+
source: string;
|
|
120
|
+
sessionId: any;
|
|
121
|
+
};
|
|
122
|
+
}>;
|
|
123
|
+
close(): Promise<void>;
|
|
124
|
+
}
|
|
125
|
+
import { EventEmitter } from "node:events";
|