@convex-dev/agent 0.1.9-alpha.4 → 0.1.9-alpha.6
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/commonjs/client/streaming.d.ts.map +1 -1
- package/dist/commonjs/client/streaming.js +1 -7
- package/dist/commonjs/client/streaming.js.map +1 -1
- package/dist/commonjs/component/_generated/api.d.ts +1 -7
- package/dist/commonjs/component/schema.d.ts +6 -36
- package/dist/commonjs/component/schema.d.ts.map +1 -1
- package/dist/commonjs/component/schema.js +0 -3
- package/dist/commonjs/component/schema.js.map +1 -1
- package/dist/commonjs/component/streams.d.ts +0 -5
- package/dist/commonjs/component/streams.d.ts.map +1 -1
- package/dist/commonjs/component/streams.js +7 -35
- package/dist/commonjs/component/streams.js.map +1 -1
- package/dist/commonjs/react/deltas.d.ts.map +1 -1
- package/dist/commonjs/react/deltas.js +1 -0
- package/dist/commonjs/react/deltas.js.map +1 -1
- package/dist/commonjs/react/index.d.ts +1 -3
- package/dist/commonjs/react/index.d.ts.map +1 -1
- package/dist/commonjs/react/index.js +3 -14
- package/dist/commonjs/react/index.js.map +1 -1
- package/dist/commonjs/validators.d.ts +2 -5
- package/dist/commonjs/validators.d.ts.map +1 -1
- package/dist/commonjs/validators.js +0 -1
- package/dist/commonjs/validators.js.map +1 -1
- package/dist/commonjs.tsbuildinfo +1 -1
- package/dist/esm/client/streaming.d.ts.map +1 -1
- package/dist/esm/client/streaming.js +1 -7
- package/dist/esm/client/streaming.js.map +1 -1
- package/dist/esm/component/_generated/api.d.ts +1 -7
- package/dist/esm/component/schema.d.ts +6 -36
- package/dist/esm/component/schema.d.ts.map +1 -1
- package/dist/esm/component/schema.js +0 -3
- package/dist/esm/component/schema.js.map +1 -1
- package/dist/esm/component/streams.d.ts +0 -5
- package/dist/esm/component/streams.d.ts.map +1 -1
- package/dist/esm/component/streams.js +7 -35
- package/dist/esm/component/streams.js.map +1 -1
- package/dist/esm/react/deltas.d.ts.map +1 -1
- package/dist/esm/react/deltas.js +1 -0
- package/dist/esm/react/deltas.js.map +1 -1
- package/dist/esm/react/index.d.ts +1 -3
- package/dist/esm/react/index.d.ts.map +1 -1
- package/dist/esm/react/index.js +3 -14
- package/dist/esm/react/index.js.map +1 -1
- package/dist/esm/validators.d.ts +2 -5
- package/dist/esm/validators.d.ts.map +1 -1
- package/dist/esm/validators.js +0 -1
- package/dist/esm/validators.js.map +1 -1
- package/dist/esm.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/client/streaming.ts +1 -7
- package/src/component/_generated/api.d.ts +1 -7
- package/src/component/schema.ts +0 -4
- package/src/component/streams.ts +8 -43
- package/src/react/deltas.ts +1 -0
- package/src/react/index.ts +4 -15
- package/src/validators.ts +0 -1
|
@@ -1414,12 +1414,6 @@ export type Mounts = {
|
|
|
1414
1414
|
>;
|
|
1415
1415
|
};
|
|
1416
1416
|
streams: {
|
|
1417
|
-
abort: FunctionReference<
|
|
1418
|
-
"mutation",
|
|
1419
|
-
"public",
|
|
1420
|
-
{ reason: string; streamId: string },
|
|
1421
|
-
null
|
|
1422
|
-
>;
|
|
1423
1417
|
addDelta: FunctionReference<
|
|
1424
1418
|
"mutation",
|
|
1425
1419
|
"public",
|
|
@@ -1575,7 +1569,7 @@ export type Mounts = {
|
|
|
1575
1569
|
list: FunctionReference<
|
|
1576
1570
|
"query",
|
|
1577
1571
|
"public",
|
|
1578
|
-
{
|
|
1572
|
+
{ threadId: string },
|
|
1579
1573
|
Array<{
|
|
1580
1574
|
agentName?: string;
|
|
1581
1575
|
model?: string;
|
package/src/component/schema.ts
CHANGED
|
@@ -109,10 +109,6 @@ export const schema = defineSchema({
|
|
|
109
109
|
kind: v.literal("finished"),
|
|
110
110
|
endedAt: v.number(),
|
|
111
111
|
}),
|
|
112
|
-
v.object({
|
|
113
|
-
kind: v.literal("aborted"),
|
|
114
|
-
reason: v.string(),
|
|
115
|
-
}),
|
|
116
112
|
v.object({
|
|
117
113
|
kind: v.literal("error"),
|
|
118
114
|
error: v.string(),
|
package/src/component/streams.ts
CHANGED
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
vStreamMessage,
|
|
7
7
|
} from "../validators.js";
|
|
8
8
|
import { api, internal } from "./_generated/api.js";
|
|
9
|
-
import type {
|
|
9
|
+
import type { Id } from "./_generated/dataModel.js";
|
|
10
10
|
import {
|
|
11
11
|
internalMutation,
|
|
12
12
|
mutation,
|
|
@@ -102,17 +102,13 @@ export const create = mutation({
|
|
|
102
102
|
export const list = query({
|
|
103
103
|
args: {
|
|
104
104
|
threadId: v.id("threads"),
|
|
105
|
-
startOrder: v.optional(v.number()),
|
|
106
105
|
},
|
|
107
106
|
returns: v.array(vStreamMessage),
|
|
108
107
|
handler: async (ctx, args) => {
|
|
109
108
|
return ctx.db
|
|
110
109
|
.query("streamingMessages")
|
|
111
110
|
.withIndex("threadId_state_order_stepOrder", (q) =>
|
|
112
|
-
q
|
|
113
|
-
.eq("threadId", args.threadId)
|
|
114
|
-
.eq("state.kind", "streaming")
|
|
115
|
-
.gte("order", args.startOrder ?? 0)
|
|
111
|
+
q.eq("threadId", args.threadId).eq("state.kind", "streaming")
|
|
116
112
|
)
|
|
117
113
|
.order("desc")
|
|
118
114
|
.take(100)
|
|
@@ -133,42 +129,6 @@ export const list = query({
|
|
|
133
129
|
},
|
|
134
130
|
});
|
|
135
131
|
|
|
136
|
-
export const abort = mutation({
|
|
137
|
-
args: {
|
|
138
|
-
streamId: v.id("streamingMessages"),
|
|
139
|
-
reason: v.string(),
|
|
140
|
-
},
|
|
141
|
-
returns: v.null(),
|
|
142
|
-
handler: async (ctx, args) => {
|
|
143
|
-
const stream = await ctx.db.get(args.streamId);
|
|
144
|
-
if (!stream) {
|
|
145
|
-
throw new Error(`Stream not found: ${args.streamId}`);
|
|
146
|
-
}
|
|
147
|
-
if (stream.state.kind !== "streaming") {
|
|
148
|
-
console.warn(
|
|
149
|
-
`Stream trying to abort but not currently streaming (${stream.state.kind}): ${args.streamId}`
|
|
150
|
-
);
|
|
151
|
-
return;
|
|
152
|
-
}
|
|
153
|
-
await cleanupTimeoutFn(ctx, stream);
|
|
154
|
-
await ctx.db.patch(args.streamId, {
|
|
155
|
-
state: { kind: "aborted", reason: args.reason },
|
|
156
|
-
});
|
|
157
|
-
},
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
async function cleanupTimeoutFn(
|
|
161
|
-
ctx: MutationCtx,
|
|
162
|
-
stream: Doc<"streamingMessages">
|
|
163
|
-
) {
|
|
164
|
-
if (stream.state.kind === "streaming" && stream.state.timeoutFnId) {
|
|
165
|
-
const timeoutFn = await ctx.db.system.get(stream.state.timeoutFnId);
|
|
166
|
-
if (timeoutFn?.state.kind === "pending") {
|
|
167
|
-
await ctx.scheduler.cancel(stream.state.timeoutFnId);
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
|
|
172
132
|
export const finish = mutation({
|
|
173
133
|
args: {
|
|
174
134
|
streamId: v.id("streamingMessages"),
|
|
@@ -189,7 +149,12 @@ export const finish = mutation({
|
|
|
189
149
|
);
|
|
190
150
|
return;
|
|
191
151
|
}
|
|
192
|
-
|
|
152
|
+
if (stream.state.timeoutFnId) {
|
|
153
|
+
const timeoutFn = await ctx.db.system.get(stream.state.timeoutFnId);
|
|
154
|
+
if (timeoutFn?.state.kind === "pending") {
|
|
155
|
+
await ctx.scheduler.cancel(stream.state.timeoutFnId);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
193
158
|
await ctx.db.patch(args.streamId, {
|
|
194
159
|
state: { kind: "finished", endedAt: Date.now() },
|
|
195
160
|
});
|
package/src/react/deltas.ts
CHANGED
package/src/react/index.ts
CHANGED
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
} from "convex/react";
|
|
8
8
|
import { usePaginatedQuery } from "convex-helpers/react";
|
|
9
9
|
import type { FunctionArgs } from "convex/server";
|
|
10
|
-
import { useMemo,
|
|
10
|
+
import { useMemo, useState } from "react";
|
|
11
11
|
import type { MessageDoc } from "../client/index.js";
|
|
12
12
|
import type { SyncStreamsReturnValue } from "../client/types.js";
|
|
13
13
|
import type { StreamArgs } from "../validators.js";
|
|
@@ -103,11 +103,7 @@ export function useThreadMessages<
|
|
|
103
103
|
ThreadMessagesArgs<Query>,
|
|
104
104
|
ThreadMessagesResult<Query>
|
|
105
105
|
>,
|
|
106
|
-
!options.stream
|
|
107
|
-
args === "skip" ||
|
|
108
|
-
paginated.status === "LoadingFirstPage"
|
|
109
|
-
? "skip"
|
|
110
|
-
: { ...args, startOrder: paginated.results.at(0)?.order }
|
|
106
|
+
!options.stream ? "skip" : args
|
|
111
107
|
);
|
|
112
108
|
|
|
113
109
|
const merged = useMemo(() => {
|
|
@@ -154,7 +150,7 @@ export function useStreamingThreadMessages<
|
|
|
154
150
|
Query extends ThreadStreamQuery<any, any>,
|
|
155
151
|
>(
|
|
156
152
|
query: Query,
|
|
157
|
-
args:
|
|
153
|
+
args: ThreadMessagesArgs<Query> | "skip"
|
|
158
154
|
): Array<ThreadMessagesResult<Query>> | undefined {
|
|
159
155
|
// Invariant: streamMessages[streamId] is comprised of all deltas up to the
|
|
160
156
|
// cursor. There can be multiple messages in the same stream, e.g. for tool
|
|
@@ -162,10 +158,6 @@ export function useStreamingThreadMessages<
|
|
|
162
158
|
const [streams, setStreams] = useState<
|
|
163
159
|
Array<{ streamId: string; cursor: number; messages: MessageDoc[] }>
|
|
164
160
|
>([]);
|
|
165
|
-
const startOrderRef = useRef<number>(0);
|
|
166
|
-
if (args !== "skip" && !startOrderRef.current && args.startOrder) {
|
|
167
|
-
startOrderRef.current = args.startOrder;
|
|
168
|
-
}
|
|
169
161
|
// Get all the active streams
|
|
170
162
|
const streamList = useQuery(
|
|
171
163
|
query,
|
|
@@ -174,10 +166,7 @@ export function useStreamingThreadMessages<
|
|
|
174
166
|
: ({
|
|
175
167
|
...args,
|
|
176
168
|
paginationOpts: { cursor: null, numItems: 0 },
|
|
177
|
-
streamArgs: {
|
|
178
|
-
kind: "list",
|
|
179
|
-
startOrder: startOrderRef.current,
|
|
180
|
-
} as StreamArgs,
|
|
169
|
+
streamArgs: { kind: "list" } as StreamArgs,
|
|
181
170
|
} as FunctionArgs<Query>)
|
|
182
171
|
) as
|
|
183
172
|
| { streams: Extract<SyncStreamsReturnValue, { kind: "list" }> }
|