lunel-cli 0.1.68 → 0.1.70
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/ai/codex.d.ts +0 -6
- package/dist/ai/codex.js +8 -109
- package/package.json +1 -1
package/dist/ai/codex.d.ts
CHANGED
|
@@ -72,13 +72,7 @@ export declare class CodexProvider implements AIProvider {
|
|
|
72
72
|
private mergeSession;
|
|
73
73
|
private upsertSession;
|
|
74
74
|
private ensureLocalSession;
|
|
75
|
-
private getTransportThreadId;
|
|
76
|
-
private findSessionByThreadId;
|
|
77
75
|
private ensureThreadResumed;
|
|
78
|
-
private shouldTreatAsThreadNotFound;
|
|
79
|
-
private ensurePromptSessionReady;
|
|
80
|
-
private createContinuationSession;
|
|
81
|
-
private handleMissingThread;
|
|
82
76
|
private resolveSessionFromPayload;
|
|
83
77
|
private resolveInFlightTurnId;
|
|
84
78
|
private decodeMessagesFromThreadRead;
|
package/dist/ai/codex.js
CHANGED
|
@@ -102,9 +102,8 @@ export class CodexProvider {
|
|
|
102
102
|
}
|
|
103
103
|
async getMessages(sessionId) {
|
|
104
104
|
const session = this.ensureLocalSession(sessionId);
|
|
105
|
-
const transportThreadId = this.getTransportThreadId(session);
|
|
106
105
|
const result = await this.call("thread/read", {
|
|
107
|
-
threadId:
|
|
106
|
+
threadId: session.id,
|
|
108
107
|
includeTurns: true,
|
|
109
108
|
});
|
|
110
109
|
const threadObject = this.extractThreadObject(result);
|
|
@@ -121,7 +120,6 @@ export class CodexProvider {
|
|
|
121
120
|
createdAt: this.extractCreatedAt(threadObject) ?? session.createdAt,
|
|
122
121
|
updatedAt: this.extractUpdatedAt(threadObject) ?? session.updatedAt,
|
|
123
122
|
archived: false,
|
|
124
|
-
transportThreadId,
|
|
125
123
|
cwd: this.extractThreadCwd(threadObject) ?? session.cwd,
|
|
126
124
|
});
|
|
127
125
|
return { messages: session.messages };
|
|
@@ -131,12 +129,12 @@ export class CodexProvider {
|
|
|
131
129
|
session.updatedAt = Date.now();
|
|
132
130
|
(async () => {
|
|
133
131
|
try {
|
|
134
|
-
|
|
132
|
+
await this.ensureThreadResumed(session.id);
|
|
135
133
|
let imageUrlKey = "url";
|
|
136
134
|
while (true) {
|
|
137
135
|
try {
|
|
138
136
|
await this.call("turn/start", {
|
|
139
|
-
threadId:
|
|
137
|
+
threadId: session.id,
|
|
140
138
|
input: this.makeTurnInputPayload(text, files, imageUrlKey),
|
|
141
139
|
...(model ? { model: model.providerID === "codex" ? model.modelID : `${model.providerID}/${model.modelID}` } : {}),
|
|
142
140
|
...(agent ? { agent } : {}),
|
|
@@ -144,11 +142,6 @@ export class CodexProvider {
|
|
|
144
142
|
break;
|
|
145
143
|
}
|
|
146
144
|
catch (err) {
|
|
147
|
-
if (this.shouldTreatAsThreadNotFound(err)) {
|
|
148
|
-
targetSession = await this.createContinuationSession(targetSession);
|
|
149
|
-
imageUrlKey = "url";
|
|
150
|
-
continue;
|
|
151
|
-
}
|
|
152
145
|
if (imageUrlKey === "url"
|
|
153
146
|
&& files.length > 0
|
|
154
147
|
&& this.shouldRetryTurnStartWithImageURLField(err)) {
|
|
@@ -169,13 +162,12 @@ export class CodexProvider {
|
|
|
169
162
|
}
|
|
170
163
|
async abort(sessionId) {
|
|
171
164
|
const session = this.ensureLocalSession(sessionId);
|
|
172
|
-
const
|
|
173
|
-
const turnId = session.activeTurnId ?? await this.resolveInFlightTurnId(transportThreadId);
|
|
165
|
+
const turnId = session.activeTurnId ?? await this.resolveInFlightTurnId(session.id);
|
|
174
166
|
if (!turnId) {
|
|
175
167
|
throw new Error(`Session ${sessionId} has no active interruptible Codex turn`);
|
|
176
168
|
}
|
|
177
169
|
session.activeTurnId = turnId;
|
|
178
|
-
await this.call("turn/interrupt", { threadId:
|
|
170
|
+
await this.call("turn/interrupt", { threadId: session.id, turnId });
|
|
179
171
|
return {};
|
|
180
172
|
}
|
|
181
173
|
async agents() {
|
|
@@ -673,9 +665,8 @@ export class CodexProvider {
|
|
|
673
665
|
}
|
|
674
666
|
async refreshSessionMetadata(sessionId) {
|
|
675
667
|
const session = this.sessions.get(sessionId);
|
|
676
|
-
const transportThreadId = session ? this.getTransportThreadId(session) : sessionId;
|
|
677
668
|
const result = await this.call("thread/read", {
|
|
678
|
-
threadId:
|
|
669
|
+
threadId: sessionId,
|
|
679
670
|
includeTurns: false,
|
|
680
671
|
});
|
|
681
672
|
const threadObject = this.extractThreadObject(result);
|
|
@@ -688,7 +679,6 @@ export class CodexProvider {
|
|
|
688
679
|
createdAt: this.extractCreatedAt(threadObject) ?? session?.createdAt ?? Date.now(),
|
|
689
680
|
updatedAt: this.extractUpdatedAt(threadObject) ?? session?.updatedAt ?? Date.now(),
|
|
690
681
|
archived: false,
|
|
691
|
-
transportThreadId,
|
|
692
682
|
cwd: this.extractThreadCwd(threadObject) ?? session?.cwd,
|
|
693
683
|
}, true);
|
|
694
684
|
}
|
|
@@ -815,7 +805,6 @@ export class CodexProvider {
|
|
|
815
805
|
createdAt: input.createdAt ?? Date.now(),
|
|
816
806
|
updatedAt: input.updatedAt ?? Date.now(),
|
|
817
807
|
archived: input.archived ?? false,
|
|
818
|
-
transportThreadId: input.transportThreadId ?? input.id,
|
|
819
808
|
cwd: input.cwd,
|
|
820
809
|
messages: [],
|
|
821
810
|
};
|
|
@@ -826,19 +815,17 @@ export class CodexProvider {
|
|
|
826
815
|
? Math.max(existing.updatedAt, input.updatedAt)
|
|
827
816
|
: existing.updatedAt;
|
|
828
817
|
existing.archived = input.archived ?? existing.archived ?? false;
|
|
829
|
-
existing.transportThreadId = input.transportThreadId ?? input.id ?? existing.transportThreadId ?? existing.id;
|
|
830
818
|
existing.cwd = input.cwd ?? existing.cwd;
|
|
831
819
|
return existing;
|
|
832
820
|
}
|
|
833
821
|
upsertSession(input, emitUpdated = false) {
|
|
834
|
-
const existing = this.
|
|
822
|
+
const existing = this.sessions.get(input.id);
|
|
835
823
|
const before = existing
|
|
836
824
|
? {
|
|
837
825
|
title: existing.title,
|
|
838
826
|
createdAt: existing.createdAt,
|
|
839
827
|
updatedAt: existing.updatedAt,
|
|
840
828
|
archived: existing.archived ?? false,
|
|
841
|
-
transportThreadId: existing.transportThreadId ?? existing.id,
|
|
842
829
|
cwd: existing.cwd,
|
|
843
830
|
}
|
|
844
831
|
: null;
|
|
@@ -849,7 +836,6 @@ export class CodexProvider {
|
|
|
849
836
|
|| before.createdAt !== session.createdAt
|
|
850
837
|
|| before.updatedAt !== session.updatedAt
|
|
851
838
|
|| before.archived !== (session.archived ?? false)
|
|
852
|
-
|| before.transportThreadId !== (session.transportThreadId ?? session.id)
|
|
853
839
|
|| before.cwd !== session.cwd;
|
|
854
840
|
if (emitUpdated && changed) {
|
|
855
841
|
this.emitter?.({ type: "session.updated", properties: { info: this.toSessionInfo(session) } });
|
|
@@ -862,20 +848,6 @@ export class CodexProvider {
|
|
|
862
848
|
return existing;
|
|
863
849
|
return this.upsertSession({ id: sessionId, title: "Conversation", createdAt: Date.now(), updatedAt: Date.now() });
|
|
864
850
|
}
|
|
865
|
-
getTransportThreadId(session) {
|
|
866
|
-
return session.transportThreadId ?? session.id;
|
|
867
|
-
}
|
|
868
|
-
findSessionByThreadId(threadId) {
|
|
869
|
-
const direct = this.sessions.get(threadId);
|
|
870
|
-
if (direct)
|
|
871
|
-
return direct;
|
|
872
|
-
for (const session of this.sessions.values()) {
|
|
873
|
-
if ((session.transportThreadId ?? session.id) === threadId) {
|
|
874
|
-
return session;
|
|
875
|
-
}
|
|
876
|
-
}
|
|
877
|
-
return undefined;
|
|
878
|
-
}
|
|
879
851
|
async ensureThreadResumed(threadId) {
|
|
880
852
|
if (!threadId || this.resumedThreadIds.has(threadId)) {
|
|
881
853
|
return;
|
|
@@ -883,84 +855,11 @@ export class CodexProvider {
|
|
|
883
855
|
await this.call("thread/resume", { threadId });
|
|
884
856
|
this.resumedThreadIds.add(threadId);
|
|
885
857
|
}
|
|
886
|
-
shouldTreatAsThreadNotFound(error) {
|
|
887
|
-
const message = (error instanceof Error ? error.message : String(error)).toLowerCase();
|
|
888
|
-
if (message.includes("not materialized") || message.includes("not yet materialized")) {
|
|
889
|
-
return false;
|
|
890
|
-
}
|
|
891
|
-
return (message.includes("thread not found")
|
|
892
|
-
|| message.includes("unknown thread")
|
|
893
|
-
|| message.includes("no rollout found for thread id")
|
|
894
|
-
|| message.includes("no rollout found"));
|
|
895
|
-
}
|
|
896
|
-
async ensurePromptSessionReady(session) {
|
|
897
|
-
const threadId = this.getTransportThreadId(session);
|
|
898
|
-
try {
|
|
899
|
-
await this.ensureThreadResumed(threadId);
|
|
900
|
-
return session;
|
|
901
|
-
}
|
|
902
|
-
catch (error) {
|
|
903
|
-
if (!this.shouldTreatAsThreadNotFound(error)) {
|
|
904
|
-
throw error;
|
|
905
|
-
}
|
|
906
|
-
return this.createContinuationSession(session);
|
|
907
|
-
}
|
|
908
|
-
}
|
|
909
|
-
async createContinuationSession(session) {
|
|
910
|
-
const previousThreadId = this.getTransportThreadId(session);
|
|
911
|
-
this.handleMissingThread(session);
|
|
912
|
-
const result = await this.call("thread/start", {
|
|
913
|
-
...(session.cwd ? { cwd: session.cwd } : { cwd: process.cwd() }),
|
|
914
|
-
});
|
|
915
|
-
const threadId = this.extractThreadId(result);
|
|
916
|
-
if (!threadId) {
|
|
917
|
-
throw new Error("thread/start response missing threadId");
|
|
918
|
-
}
|
|
919
|
-
session.transportThreadId = threadId;
|
|
920
|
-
session.updatedAt = Date.now();
|
|
921
|
-
session.archived = false;
|
|
922
|
-
this.upsertSession({
|
|
923
|
-
id: session.id,
|
|
924
|
-
title: this.extractThreadTitleFromUnknown(result) ?? session.title,
|
|
925
|
-
createdAt: session.createdAt,
|
|
926
|
-
updatedAt: this.extractUpdatedAt(result) ?? Date.now(),
|
|
927
|
-
archived: false,
|
|
928
|
-
transportThreadId: threadId,
|
|
929
|
-
cwd: this.extractThreadCwd(result) ?? session.cwd ?? process.cwd(),
|
|
930
|
-
}, true);
|
|
931
|
-
this.resumedThreadIds.add(threadId);
|
|
932
|
-
const systemMessageId = `system:${crypto.randomUUID()}`;
|
|
933
|
-
session.messages.push({
|
|
934
|
-
id: systemMessageId,
|
|
935
|
-
role: "assistant",
|
|
936
|
-
parts: [{
|
|
937
|
-
id: `${systemMessageId}:text`,
|
|
938
|
-
type: "text",
|
|
939
|
-
text: `Continued from archived thread \`${previousThreadId}\``,
|
|
940
|
-
sessionID: session.id,
|
|
941
|
-
messageID: systemMessageId,
|
|
942
|
-
}],
|
|
943
|
-
time: Date.now(),
|
|
944
|
-
});
|
|
945
|
-
this.emitMessagePartEvent(session.id, systemMessageId, "assistant", {
|
|
946
|
-
id: `${systemMessageId}:text`,
|
|
947
|
-
type: "text",
|
|
948
|
-
text: `Continued from archived thread \`${previousThreadId}\``,
|
|
949
|
-
sessionID: session.id,
|
|
950
|
-
messageID: systemMessageId,
|
|
951
|
-
});
|
|
952
|
-
return session;
|
|
953
|
-
}
|
|
954
|
-
handleMissingThread(session) {
|
|
955
|
-
const threadId = this.getTransportThreadId(session);
|
|
956
|
-
this.resumedThreadIds.delete(threadId);
|
|
957
|
-
session.activeTurnId = undefined;
|
|
958
|
-
}
|
|
959
858
|
resolveSessionFromPayload(payload) {
|
|
960
859
|
const threadId = this.extractThreadId(payload);
|
|
961
860
|
if (!threadId)
|
|
962
861
|
return undefined;
|
|
963
|
-
return this.
|
|
862
|
+
return this.ensureLocalSession(threadId);
|
|
964
863
|
}
|
|
965
864
|
async resolveInFlightTurnId(threadId) {
|
|
966
865
|
const result = await this.call("thread/read", { threadId, includeTurns: true });
|