@letta-ai/letta-react 0.2.0 → 0.2.2

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/README.md CHANGED
@@ -26,16 +26,17 @@ function App() {
26
26
  }
27
27
  ```
28
28
 
29
- Then you can use `useLetta` and `useLettaQuery` hooks to interact with the Letta API.
29
+ Then you can use `useLettaQuery` hooks to interact with the Letta API.
30
30
 
31
31
  ```tsx
32
32
  import { useLetta, useLettaQuery } from '@letta-ai/letta-react';
33
33
 
34
34
  function YourComponent() {
35
- const client = useLetta();
36
35
  const { data, isLoading, error } = useLettaQuery(
37
- (args) => client.agents.list(args),
38
- { limit: 1 }
36
+ // the first argument exposes a client instantiation
37
+ (client) => client.agents.list({ limit: 1 }),
38
+ // the rest of the argumenst are the same as react-query, so you should specify a queryKey
39
+ { queryKey: ['agents', 'list'] }
39
40
  );
40
41
 
41
42
  if (isLoading) return <div>Loading...</div>;
@@ -45,50 +46,6 @@ function YourComponent() {
45
46
  }
46
47
  ```
47
48
 
48
- The `useLetta` hook returns the Letta client instance, which you can use to call any of the API methods. The `useLettaQuery` hook is a wrapper around the `useQuery` hook from tanstack/react-query, which allows you to easily fetch data from the Letta API and manage the loading and error states.
49
-
50
- The format of the `useLettaQuery` hook is as follows:
51
-
52
- ```tsx
53
- useLettaQuery(
54
- operation // the client operation you want to call, this should be 1:1 match with our API docs, it __must__ be wrapped in a function
55
- args, // the arguments to pass to the operation
56
- options // optional react-query options
57
- )
58
- ```
59
-
60
- ## Examples
61
-
62
- ### List Agents
63
-
64
- 1. First let's go to the [API docs](https://docs.letta.ai/api-reference/agents/list) and see the API for listing agents.
65
-
66
- ```ts
67
- import { LettaClient } from '@letta-ai/letta-client';
68
- const client = new LettaClient({ token: 'YOUR_TOKEN' });
69
- await client.agents.list();
70
- ```
71
-
72
- As we can see, we can call the `list` method on the `agents` object to get a list of agents. The `list` method takes an optional `args`.
73
-
74
- 2. Now let's translate the usage to use the `useLettaQuery` hook to call this API in a React component.
75
-
76
- ```tsx
77
- import { useLetta, useLettaQuery } from '@letta-ai/letta-react';
78
-
79
- function YourComponent() {
80
- const client = useLetta();
81
- const { data, isLoading, error } = useLettaQuery((args) =>
82
- client.agents.list(args)
83
- );
84
-
85
- if (isLoading) return <div>Loading...</div>;
86
- if (error) return <div>Error: {error.message}</div>;
87
-
88
- return <div>Data: {JSON.stringify(data)}</div>;
89
- }
90
- ```
91
-
92
49
  # Future Work
93
50
 
94
51
  This library only supports queries not mutations at the moment. Please use this library in conjunction with [@letta-ai/vercel-ai-sdk-provider](https://www.npmjs.com/package/@letta-ai/vercel-ai-sdk-provider) for a full experience.
package/dist/index.d.ts CHANGED
@@ -1,2 +1 @@
1
1
  export * from './useLettaQuery/useLettaQuery';
2
- export * from './useLetta/useLetta';
package/dist/index.js CHANGED
@@ -48254,30 +48254,24 @@ var require_letta_client = __commonJS({
48254
48254
  });
48255
48255
 
48256
48256
  // src/useLettaQuery/useLettaQuery.ts
48257
+ var import_letta_client = __toESM(require_letta_client());
48257
48258
  import { useQuery } from "@tanstack/react-query";
48258
- function getQueryKey(operationName, request) {
48259
- return [operationName, request];
48260
- }
48261
- function useLettaQuery(operation, request, options, queryOptions = {}) {
48259
+ import { useRef } from "react";
48260
+ function useLettaQuery(operation, queryOptions) {
48261
+ const client = useRef(
48262
+ new import_letta_client.LettaClient({
48263
+ // force to use the default base URL, you should by proxy it in your server
48264
+ baseUrl: "/"
48265
+ })
48266
+ );
48262
48267
  return useQuery({
48263
- queryKey: getQueryKey(operation.name, request),
48264
- queryFn: () => {
48265
- return operation(request, options);
48266
- },
48267
- ...queryOptions || {}
48268
+ ...queryOptions,
48269
+ queryFn: async () => {
48270
+ return operation(client.current);
48271
+ }
48268
48272
  });
48269
48273
  }
48270
-
48271
- // src/useLetta/useLetta.ts
48272
- var import_letta_client = __toESM(require_letta_client());
48273
- import { useState } from "react";
48274
- function useLetta(options = {}) {
48275
- const [client] = useState(new import_letta_client.LettaClient(options));
48276
- return client;
48277
- }
48278
48274
  export {
48279
- getQueryKey,
48280
- useLetta,
48281
48275
  useLettaQuery
48282
48276
  };
48283
48277
  /*! Bundled license information: