@love-moon/ai-sdk 0.2.39 → 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.
@@ -144,9 +144,10 @@ export class KimiCliSession extends EventEmitter<[never]> {
144
144
  handleTransportFailure(error: any): void;
145
145
  handleTransportExit(payload: any): void;
146
146
  interruptCurrentTurn(): Promise<boolean>;
147
- runTurn(promptText: any, { useInitialImages, onProgress }?: {
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();
@@ -823,11 +832,14 @@ export class KimiCliSession extends EventEmitter {
823
832
  }
824
833
  return false;
825
834
  }
826
- async runTurn(promptText, { useInitialImages = false, onProgress = null } = {}) {
835
+ async runTurn(promptText, { useInitialImages = false, onProgress = null, jsonSchema = null } = {}) {
827
836
  if (this.closeRequested || this.closed) {
828
837
  throw this.createSessionClosedError();
829
838
  }
830
- const effectivePrompt = this.buildPrompt(promptText, { useInitialImages });
839
+ let effectivePrompt = this.buildPrompt(promptText, { useInitialImages });
840
+ if (jsonSchema && typeof jsonSchema === "object" && effectivePrompt) {
841
+ effectivePrompt = injectJsonSchemaPrompt(effectivePrompt, jsonSchema);
842
+ }
831
843
  if (!effectivePrompt) {
832
844
  return buildEmptyTurnResult();
833
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";