whoami
whoami
CCConvex Community
Created by whoami on 6/12/2023 in #support-community
Can I do langchain streaming in convex?
Haven't tried that yet but wanted to know if that's possible with convex actions
3 replies
CCConvex Community
Created by whoami on 6/12/2023 in #support-community
convex helpers need to be updated with convex 0.16
Property 'filter' in type 'WrapQuery<T>' is not assignable to the same property in base type 'Query<T>'.
Type '(predicate: (q: FilterBuilder<T>) => Expression<boolean>) => WrapQuery<T>' is not assignable to type '(predicate: (q: FilterBuilder<T>) => ExpressionOrValue<boolean>) => this'.
Type 'WrapQuery<T>' is not assignable to type 'this'.
'WrapQuery<T>' is assignable to the constraint of type 'this', but 'this' could be instantiated with a different subtype of constraint 'WrapQuery<T>'.
Property 'filter' in type 'WrapQuery<T>' is not assignable to the same property in base type 'Query<T>'.
Type '(predicate: (q: FilterBuilder<T>) => Expression<boolean>) => WrapQuery<T>' is not assignable to type '(predicate: (q: FilterBuilder<T>) => ExpressionOrValue<boolean>) => this'.
Type 'WrapQuery<T>' is not assignable to type 'this'.
'WrapQuery<T>' is assignable to the constraint of type 'this', but 'this' could be instantiated with a different subtype of constraint 'WrapQuery<T>'.
filter(
predicate: (q: FilterBuilder<T>) => Expression<boolean>,
): WrapQuery<T> {
return new WrapQuery(this.q.filter(predicate), this.p)
}
filter(
predicate: (q: FilterBuilder<T>) => Expression<boolean>,
): WrapQuery<T> {
return new WrapQuery(this.q.filter(predicate), this.p)
}
https://github.com/get-convex/convex-helpers/blob/4360d3e57a622e293407c9293a1fc745cc731dbe/convex/lib/rowLevelSecurity.ts
2 replies
CCConvex Community
Created by whoami on 5/28/2023 in #support-community
Refresh clerk auth token when I switch orgs
I am encountering an issue when attempting to implement row level security with your recommended approach. I've taken the step of feeding the org_id to the gender field in the JWT provided by the clerk. However, I am finding that the token is not refreshing immediately after switching organizations. In my code, I switch the organization, which prompts the clerk hook to reflect the change:
const { organization: org } = useOrganization({})
const { organization: org } = useOrganization({})
As expected, org?.id is passed to the query reactively when I switch organizations. However, I've noticed that the JWT's gender field, where I've assigned the org_id, doesn't appear to refresh to the new organization's ID in sync. This discrepancy is causing my chat list to return as empty. Here's my query code
const data = useQuery('chats:list', {
org: org?.id || '',
})
const data = useQuery('chats:list', {
org: org?.id || '',
})
Here is my RLS code
export const { withQueryRLS, withMutationRLS } = RowLevelSecurity<
{ auth: Auth; db: DatabaseReader },
DataModel
>({
chats: {
read: async ({ auth }, chat) => {
const identity = await auth.getUserIdentity()
if (!identity) {
throw new Error('Unauthenticated call to mutation')
}
const { gender: org } = identity
return chat.org === org
},
...
export const { withQueryRLS, withMutationRLS } = RowLevelSecurity<
{ auth: Auth; db: DatabaseReader },
DataModel
>({
chats: {
read: async ({ auth }, chat) => {
const identity = await auth.getUserIdentity()
if (!identity) {
throw new Error('Unauthenticated call to mutation')
}
const { gender: org } = identity
return chat.org === org
},
...
I need the JWT to refresh immediately after an organization switch to ensure the correct data is being accessed.
7 replies
CCConvex Community
Created by whoami on 5/22/2023 in #support-community
Langchain + convex action
While langchain's pdf-loader works with use node directive, my following code won't work in both js and node env.
import { v } from "convex/values"
import { ChatOpenAI } from "langchain/chat_models/openai"
import { HumanChatMessage } from "langchain/dist/schema"

import { action } from "./_generated/server"

export const extract = action({
args: {
report: v.id("reports"),
},
handler: async ({ runMutation, runQuery }, { report }) => {
const docs = "..."
const chat = new ChatOpenAI({ temperature: 0 })

const response = await chat.call([
new HumanChatMessage(`Translate the doc: ${docs}`),
])

runMutation("reports:patch", { id: report, insights: [response.text] })
},
})
import { v } from "convex/values"
import { ChatOpenAI } from "langchain/chat_models/openai"
import { HumanChatMessage } from "langchain/dist/schema"

import { action } from "./_generated/server"

export const extract = action({
args: {
report: v.id("reports"),
},
handler: async ({ runMutation, runQuery }, { report }) => {
const docs = "..."
const chat = new ChatOpenAI({ temperature: 0 })

const response = await chat.call([
new HumanChatMessage(`Translate the doc: ${docs}`),
])

runMutation("reports:patch", { id: report, insights: [response.text] })
},
})
and the error is
✖ Error: Unable to bundle Convex modules
esbuild failed: Error: Build failed with 1 error:
convex/insights.ts:3:33: ERROR: Could not resolve "langchain/dist/schema"
✘ [ERROR] Could not resolve "langchain/dist/schema"

convex/insights.ts:3:33:
3 │ ... from "langchain/dist/schema"
╵ ~~~~~~~~~~~~~~~~~~~~~~~

The path "./dist/schema" is not exported
by package "langchain":

node_modules/langchain/package.json:598:13:
598 │ "exports": {
╵ ^

You can mark the path
"langchain/dist/schema" as external to
exclude it from the bundle, which will
remove this error.

✖ Error: Unable to bundle Convex modules
esbuild failed: Error: Build failed with 1 error:
convex/insights.ts:3:33: ERROR: Could not resolve "langchain/dist/schema"
✖ Error: Unable to bundle Convex modules
esbuild failed: Error: Build failed with 1 error:
convex/insights.ts:3:33: ERROR: Could not resolve "langchain/dist/schema"
✘ [ERROR] Could not resolve "langchain/dist/schema"

convex/insights.ts:3:33:
3 │ ... from "langchain/dist/schema"
╵ ~~~~~~~~~~~~~~~~~~~~~~~

The path "./dist/schema" is not exported
by package "langchain":

node_modules/langchain/package.json:598:13:
598 │ "exports": {
╵ ^

You can mark the path
"langchain/dist/schema" as external to
exclude it from the bundle, which will
remove this error.

✖ Error: Unable to bundle Convex modules
esbuild failed: Error: Build failed with 1 error:
convex/insights.ts:3:33: ERROR: Could not resolve "langchain/dist/schema"
any insights?
2 replies
CCConvex Community
Created by whoami on 5/21/2023 in #support-community
Internal error for getting blob from storageId in node runtime
I was trying langchain/document_loaders with javascript runtime, that didn't work out so I turned myself to the node runtime, this time I got
Transient error during storage get url: {"code":"InternalServerError","message":"Your request couldn't be completed. Try again later."}
at async get [as get] (../node_modules/.pnpm/convex@0.14.1_biqbaboplfbrettd7655fr4n2y/node_modules/convex/src/server/impl/storage_impl.ts:68:8)
at async handler (../convex/action.ts:16:16)
at async invokeAction (../node_modules/.pnpm/convex@0.14.1_biqbaboplfbrettd7655fr4n2y/node_modules/convex/src/server/impl/registration_impl.ts:249:14)
Transient error during storage get url: {"code":"InternalServerError","message":"Your request couldn't be completed. Try again later."}
at async get [as get] (../node_modules/.pnpm/convex@0.14.1_biqbaboplfbrettd7655fr4n2y/node_modules/convex/src/server/impl/storage_impl.ts:68:8)
at async handler (../convex/action.ts:16:16)
at async invokeAction (../node_modules/.pnpm/convex@0.14.1_biqbaboplfbrettd7655fr4n2y/node_modules/convex/src/server/impl/registration_impl.ts:249:14)
"use node"

import { v } from "convex/values"
import { PDFLoader } from "langchain/document_loaders"

import { action } from "./_generated/server"

export const save = action({
args: {
storageId: v.string(),
},
handler: async ({ runMutation, storage }, { storageId }) => {
console.log("storageId", storageId)

// I think this is where things go wrong
const blob = await storage.get(storageId)
...
},
})
"use node"

import { v } from "convex/values"
import { PDFLoader } from "langchain/document_loaders"

import { action } from "./_generated/server"

export const save = action({
args: {
storageId: v.string(),
},
handler: async ({ runMutation, storage }, { storageId }) => {
console.log("storageId", storageId)

// I think this is where things go wrong
const blob = await storage.get(storageId)
...
},
})
3 replies
CCConvex Community
Created by whoami on 5/21/2023 in #support-community
Receiving JWT fields beyond what UserIdentity provides
Hi team, we tried to implement RLS with clerk provided auth fields, I wanted to know is there any plans extending auth.getUserIdentity() to receive fields other than what UserIdentity provides? Passing org_id to gender field sounds like a hack but I suppose there should be a better way?
export const { withQueryRLS, withMutationRLS } = RowLevelSecurity<
{ auth: Auth; db: DatabaseReader },
DataModel
>({
chats: {
read: async ({ auth }, chat) => {
const identity = await auth.getUserIdentity()
if (!identity) {
throw new Error('Unauthenticated call to mutation')
}
const { gender: org } = identity
return chat.org === org
},
modify: async ({ auth }, chat) => {
const identity = await auth.getUserIdentity()
if (!identity) {
throw new Error('Unauthenticated call to mutation')
}
const { gender: org } = identity
return chat.org === org
},
},
})
export const { withQueryRLS, withMutationRLS } = RowLevelSecurity<
{ auth: Auth; db: DatabaseReader },
DataModel
>({
chats: {
read: async ({ auth }, chat) => {
const identity = await auth.getUserIdentity()
if (!identity) {
throw new Error('Unauthenticated call to mutation')
}
const { gender: org } = identity
return chat.org === org
},
modify: async ({ auth }, chat) => {
const identity = await auth.getUserIdentity()
if (!identity) {
throw new Error('Unauthenticated call to mutation')
}
const { gender: org } = identity
return chat.org === org
},
},
})
Also we've found that when passing whatever clerk values to address fields like address: {{org.id}} the auth will crash, not sure if there is any bug associated with clerk or convex.
3 replies
CCConvex Community
Created by whoami on 5/20/2023 in #support-community
Does convex work with collaborative editing?
So I was considering building a collaborative editing, ideally what something like liveblocks provides. Since you have an option for optimistic update, I am curious if you folks have done similar demo before and what is your approach with conflict resolution.
14 replies
CCConvex Community
Created by whoami on 5/18/2023 in #support-community
Bad URL errors "WebSocket closed unexpectedly with code 1006" in vercel preview env + convex dev
No description
16 replies
CCConvex Community
Created by whoami on 5/17/2023 in #support-community
Convex Compatibility Issue with Certain Browser Plugins
No description
10 replies
CCConvex Community
Created by whoami on 5/17/2023 in #support-community
Async request in Python client
Is it supported?
4 replies
CCConvex Community
Created by whoami on 5/16/2023 in #support-community
Too many open queries
Unhandled Runtime Error
Error: [CONVEX Q(chats.js:get)] Uncaught Error: Too many open queries (64 > maximum 64)
at performSyscall (../../node_modules/convex/src/server/impl/syscall.ts:21:20)
at startQuery [as startQuery] (../../node_modules/convex/src/server/impl/query_impl.ts:188:25)
at [Symbol.asyncIterator] (../../node_modules/convex/src/server/impl/query_impl.ts:235:4)
at collect [as collect] (../../node_modules/convex/src/server/impl/query_impl.ts:297:19)
at <anonymous> (../convex/chats.ts:63:15)
at map [as map]
Error: [CONVEX Q(chats.js:get)] Uncaught Error: Too many open queries (64 > maximum 64)
at performSyscall (../../node_modules/convex/src/server/impl/syscall.ts:21:20)
at startQuery [as startQuery] (../../node_modules/convex/src/server/impl/query_impl.ts:188:25)
at [Symbol.asyncIterator] (../../node_modules/convex/src/server/impl/query_impl.ts:235:4)
at collect [as collect] (../../node_modules/convex/src/server/impl/query_impl.ts:297:19)
at <anonymous> (../convex/chats.ts:63:15)
at map [as map]
Where did I do wrong? Here is my mutation that causes the error (I think) My code might be messy so any advices not related to the issue but related to my convex code in general is appreciated as well
export const get = query({
args: {
id: v.id('chats'),
},

handler: async ({ db, auth }, { id }) => {
const identity = await auth.getUserIdentity()
if (!identity) {
throw new Error('Unauthenticated call to query')
}

const chat = await db.get(id)
if (!chat) {
return {
error: 'Chat not found',
}
}

const tools = await Promise.all(chat.tools.map((t) => db.get(t)))
const messages = await db
.query('messages')
.withIndex('by_chat', (q) => q.eq('chat', id))
.order('asc')
.collect()

const messagesWithSteps = await Promise.all(
messages.map(async (m) => {
const steps = await db
.query('steps')
.withIndex('by_message', (q) => q.eq('message', m._id))
.order('asc')
.collect()

return {
...m,
steps,
}
}),
)

return {
chat: {
id: chat._id,
title: chat.title,
// get the last 100 messages
messages: messagesWithSteps.splice(
messages.length - 100,
messages.length,
),
tools,
status: chat.status,
},
}
},
})
export const get = query({
args: {
id: v.id('chats'),
},

handler: async ({ db, auth }, { id }) => {
const identity = await auth.getUserIdentity()
if (!identity) {
throw new Error('Unauthenticated call to query')
}

const chat = await db.get(id)
if (!chat) {
return {
error: 'Chat not found',
}
}

const tools = await Promise.all(chat.tools.map((t) => db.get(t)))
const messages = await db
.query('messages')
.withIndex('by_chat', (q) => q.eq('chat', id))
.order('asc')
.collect()

const messagesWithSteps = await Promise.all(
messages.map(async (m) => {
const steps = await db
.query('steps')
.withIndex('by_message', (q) => q.eq('message', m._id))
.order('asc')
.collect()

return {
...m,
steps,
}
}),
)

return {
chat: {
id: chat._id,
title: chat.title,
// get the last 100 messages
messages: messagesWithSteps.splice(
messages.length - 100,
messages.length,
),
tools,
status: chat.status,
},
}
},
})
14 replies
CCConvex Community
Created by whoami on 5/15/2023 in #support-community
Use `v.` schema to validate object types?
How do I use the v. schema defined in schema.ts and use it to validate typescript object types? So I do not need to define a zod schema again, or maybe you will support zod schema in the future?
11 replies
CCConvex Community
Created by whoami on 5/11/2023 in #support-community
Firefox can’t establish a connection to the server at wss://.../api/0.14
I am frequently getting this the error in the title while developing with convex along with
WebSocket closed unexpectedly with code 1006 next-dev.js:23:26
error webpack-internal:///../../node_modules/next/dist/client/next-dev.js:23
overrideMethod moz-extension://8b846726-665b-46d4-910c-79fac2e24176/build/react_devtools_backend.js:4012
onclose webpack-internal:///../../node_modules/convex/dist/esm/browser/sync/web_socket_manager.js:90
(Async: EventHandlerNonNull)
connect webpack-internal:///../../node_modules/convex/dist/esm/browser/sync/web_socket_manager.js:80
WebSocketManager webpack-internal:///../../node_modules/convex/dist/esm/browser/sync/web_socket_manager.js:34
BaseConvexClient webpack-internal:///../../node_modules/convex/dist/esm/browser/sync/client.js:112
get sync webpack-internal:///../../node_modules/convex/dist/esm/react/client.js:72
setAuth webpack-internal:///../../node_modules/convex/dist/esm/react/client.js:88
setToken webpack-internal:///../../node_modules/convex/dist/esm/react/ConvexAuthState.js:25
ConvexProviderWithAuth webpack-internal:///../../node_modules/convex/dist/esm/react/ConvexAuthState.js:32
React 13
commitHookEffectListMount
commitPassiveMountOnFiber
commitPassiveMountEffects_complete
commitPassiveMountEffects_begin
commitPassiveMountEffects
flushPassiveEffectsImpl
flushPassiveEffects
performSyncWorkOnRoot
flushSyncCallbacks
commitRootImpl
commitRoot
finishConcurrentRender
performConcurrentWorkOnRoot
workLoop webpack-
WebSocket closed unexpectedly with code 1006 next-dev.js:23:26
error webpack-internal:///../../node_modules/next/dist/client/next-dev.js:23
overrideMethod moz-extension://8b846726-665b-46d4-910c-79fac2e24176/build/react_devtools_backend.js:4012
onclose webpack-internal:///../../node_modules/convex/dist/esm/browser/sync/web_socket_manager.js:90
(Async: EventHandlerNonNull)
connect webpack-internal:///../../node_modules/convex/dist/esm/browser/sync/web_socket_manager.js:80
WebSocketManager webpack-internal:///../../node_modules/convex/dist/esm/browser/sync/web_socket_manager.js:34
BaseConvexClient webpack-internal:///../../node_modules/convex/dist/esm/browser/sync/client.js:112
get sync webpack-internal:///../../node_modules/convex/dist/esm/react/client.js:72
setAuth webpack-internal:///../../node_modules/convex/dist/esm/react/client.js:88
setToken webpack-internal:///../../node_modules/convex/dist/esm/react/ConvexAuthState.js:25
ConvexProviderWithAuth webpack-internal:///../../node_modules/convex/dist/esm/react/ConvexAuthState.js:32
React 13
commitHookEffectListMount
commitPassiveMountOnFiber
commitPassiveMountEffects_complete
commitPassiveMountEffects_begin
commitPassiveMountEffects
flushPassiveEffectsImpl
flushPassiveEffects
performSyncWorkOnRoot
flushSyncCallbacks
commitRootImpl
commitRoot
finishConcurrentRender
performConcurrentWorkOnRoot
workLoop webpack-
17 replies
CCConvex Community
Created by whoami on 5/7/2023 in #support-community
Is there a way to get the progress of file uploading in convex storage?
Something like this, provided by upload.io
const uploadResult = await uploader.uploadFile(file, {
onProgress: (p) => {
setUploadProgress(p.progress)
},
})
const uploadResult = await uploader.uploadFile(file, {
onProgress: (p) => {
setUploadProgress(p.progress)
},
})
15 replies
CCConvex Community
Created by whoami on 5/7/2023 in #support-community
Supporting cascades delete in convex?
As I was searching for the cascades keyword in the channel, I there was a discussion on the case https://discord.com/channels/1019350475847499849/1067581483243544627/1067584500063817729 I am wondering if you guys have any plans / roadmap on supporting this and many other features that are commonly available in relational database. I know there is a no free lunch theorem, but I simply believe with convex or any fast evolving infrastructure of the future, we can have our cake and eat it too : )
6 replies
CCConvex Community
Created by whoami on 5/7/2023 in #support-community
Staging environment for convex?
I love how individual developers got their own dev environment with convex, the developer experience has never been easier, this is great! Any suggestions on the best practice for handling staging environment before the manual push to the production? local / preview / production
7 replies
CCConvex Community
Created by whoami on 5/6/2023 in #support-community
Passing clerk generated token to python client?
I generated a token from clerk in react and passed it to a Python service
token = ... # passed from clerk in react
convex = ConvexClient(os.environ["CONVEX_URL"])
convex.set_auth(token)
chat = convex.query(
"chats:get", {'id': Id('chats', input.chat_id)}
) # this line failed
token = ... # passed from clerk in react
convex = ConvexClient(os.environ["CONVEX_URL"])
convex.set_auth(token)
chat = convex.query(
"chats:get", {'id': Id('chats', input.chat_id)}
) # this line failed
These are errors I got
Traceback (most recent call last):
File "/Users/miniforge3/envs/askstring/lib/python3.11/site-packages/convex/__init__.py", line 94, in _request
r.raise_for_status()
File "/Users/miniforge3/envs/askstring/lib/python3.11/site-packages/requests/models.py", line 1021, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: https://clean-dinosaur-909.convex.cloud/api/query
Traceback (most recent call last):
File "/Users/miniforge3/envs/askstring/lib/python3.11/site-packages/convex/__init__.py", line 94, in _request
r.raise_for_status()
File "/Users/miniforge3/envs/askstring/lib/python3.11/site-packages/requests/models.py", line 1021, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: https://clean-dinosaur-909.convex.cloud/api/query
I am using dev env and I am pretty sure the url I used in both frontend and backend is consistent. And what's more interesting is, when I removed convex.set_auth(token), the code ran through. I am really confused right now, what are we doing with the token if this is not required? Why providing a token will instead lead to the auth failure?
37 replies
CCConvex Community
Created by whoami on 5/5/2023 in #support-community
How to do convert between Id in string format and `Id<'...'>`?
Question is in the title
25 replies
CCConvex Community
Created by whoami on 4/17/2023 in #support-community
Best practice for modeling many to many, one to many relationships as in relational database
I am looking for examples/demos on modeling such relationships and queries at ease, but didn't find much mentioning those in the doc. I am looking for prisma like API to assist me queries like get me the most recent posts along with their user's email address, if there are anything sample demo project link you can provide me with, I am more than appreciated.
12 replies
CCConvex Community
Created by whoami on 4/17/2023 in #support-community
Usage in Python client
Is there any detailed example/demo on python client? How do I pass Id<Chat> in python client? This is my function definition under convex/ask.ts
export const insert = mutationz(
{
chat: zconvex.id('chat'),
content: z.string().nonempty().max(256),
},
...
export const insert = mutationz(
{
chat: zconvex.id('chat'),
content: z.string().nonempty().max(256),
},
...
and I was trying to call it in Python via
convex_client.mutation('ask:insert', {'chat': {'tableName': 'chat', 'id': '...'}, 'content': '...'})
convex_client.mutation('ask:insert', {'chat': {'tableName': 'chat', 'id': '...'}, 'content': '...'})
but got no luck
Uncaught ZodError: [
{
"code": "invalid_arguments",
"argumentsError": {
"issues": [
{
"code": "custom",
"fatal": true,
"path": [
0,
"chat"
],
"message": "Invalid input"
}
],
"name": "ZodError"
},
"path": [],
"message": "Invalid function arguments"
}
]
Uncaught ZodError: [
{
"code": "invalid_arguments",
"argumentsError": {
"issues": [
{
"code": "custom",
"fatal": true,
"path": [
0,
"chat"
],
"message": "Invalid input"
}
],
"name": "ZodError"
},
"path": [],
"message": "Invalid function arguments"
}
]
6 replies