@kortix/sdk 0.13.19 → 0.13.20
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/core/client/kortix.d.ts +5 -0
- package/dist/core/client/kortix.d.ts.map +1 -1
- package/dist/core/client/kortix.js +5 -0
- package/dist/core/client/kortix.js.map +1 -1
- package/dist/core/http/api-client.d.ts +7 -0
- package/dist/core/http/api-client.d.ts.map +1 -1
- package/dist/core/http/api-client.js +1 -0
- package/dist/core/http/api-client.js.map +1 -1
- package/dist/core/rest/projects-client/sessions.d.ts +52 -4
- package/dist/core/rest/projects-client/sessions.d.ts.map +1 -1
- package/dist/core/rest/projects-client/sessions.js +55 -5
- package/dist/core/rest/projects-client/sessions.js.map +1 -1
- package/dist/kortix.esm.min.js +18 -18
- package/dist/kortix.global.js +18 -18
- package/dist/react/index.d.ts +2 -0
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +2 -0
- package/dist/react/index.js.map +1 -1
- package/dist/react/query-keys.d.ts +17 -0
- package/dist/react/query-keys.d.ts.map +1 -1
- package/dist/react/query-keys.js +17 -0
- package/dist/react/query-keys.js.map +1 -1
- package/dist/react/session-cache-write.d.ts +57 -0
- package/dist/react/session-cache-write.d.ts.map +1 -0
- package/dist/react/session-cache-write.js +118 -0
- package/dist/react/session-cache-write.js.map +1 -0
- package/dist/react/use-project-sessions.d.ts +315 -0
- package/dist/react/use-project-sessions.d.ts.map +1 -0
- package/dist/react/use-project-sessions.js +94 -0
- package/dist/react/use-project-sessions.js.map +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-project-sessions.d.ts","sourceRoot":"","sources":["../../src/react/use-project-sessions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,EAEL,KAAK,0BAA0B,EAC/B,KAAK,cAAc,EACnB,KAAK,kBAAkB,EACxB,MAAM,uCAAuC,CAAC;AAI/C;;;;;GAKG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,kBAAkB,GAAG,MAAM,GAAG,SAAS,CAErF;AAED;;;;;;;;;GASG;AACH,wBAAgB,0BAA0B,CACxC,IAAI,EAAE;IAAE,KAAK,EAAE,kBAAkB,EAAE,CAAC;IAAC,UAAU,EAAE,OAAO,EAAE,CAAA;CAAE,GAAG,SAAS,GACvE,cAAc,EAAE,CAYlB;AAED,MAAM,WAAW,yBACf,SAAQ,IAAI,CAAC,0BAA0B,EAAE,OAAO,GAAG,OAAO,CAAC;IAC3D,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,4EAA4E;IAC5E,eAAe,CAAC,EAAE,MAAM,GAAG,KAAK,GAAG,CAAC,CAAC,QAAQ,EAAE,cAAc,EAAE,KAAK,MAAM,GAAG,KAAK,CAAC,CAAC;IACpF,oBAAoB,CAAC,EAAE,OAAO,CAAC;CAChC;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,yBAAyB;IAwBrF;;;;;;;OAOG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAPH;;;;;;;OAOG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAPH;;;;;;;OAOG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAPH;;;;;;;OAOG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAPH;;;;;;;OAOG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAPH;;;;;;;OAOG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAGN"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The project session list, paged.
|
|
3
|
+
*
|
|
4
|
+
* `GET /projects/:id/sessions` used to answer with every session row the viewer
|
|
5
|
+
* could see. On a project that had accumulated 12,617 sessions that is a
|
|
6
|
+
* multi-megabyte body — and the sidebar re-fetches this list every 5 seconds
|
|
7
|
+
* for as long as ANY one row sits in `queued`/`branching`/`provisioning`, which
|
|
8
|
+
* over twelve thousand rows is effectively always. The browser paid three times
|
|
9
|
+
* per tick: parsing the body, letting react-query structurally share 12k
|
|
10
|
+
* objects, then re-sorting and re-grouping them into sections.
|
|
11
|
+
*
|
|
12
|
+
* The list is now a bounded keyset page (`listProjectSessionsPage`). This module
|
|
13
|
+
* holds the two pure pieces of the `useInfiniteQuery` wiring so they can be
|
|
14
|
+
* tested without mounting react-query, plus the hook itself.
|
|
15
|
+
*/
|
|
16
|
+
import { useInfiniteQuery } from '@tanstack/react-query';
|
|
17
|
+
import { listProjectSessionsPage, } from '../core/rest/projects-client/sessions.js';
|
|
18
|
+
import { qk } from './query-keys.js';
|
|
19
|
+
import { contract } from './query-contracts.js';
|
|
20
|
+
/**
|
|
21
|
+
* `getNextPageParam`. Returns `undefined` — not `null` — at the end of the
|
|
22
|
+
* list: `undefined` is what react-query reads as "no more pages", and it is
|
|
23
|
+
* what makes `hasNextPage` go false. Handing back `null` leaves `hasNextPage`
|
|
24
|
+
* true and a Load-more button that re-fetches page one forever.
|
|
25
|
+
*/
|
|
26
|
+
export function projectSessionsPageParam(page) {
|
|
27
|
+
return page.next_cursor ?? undefined;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Flatten the fetched pages into the flat array every consumer of this list
|
|
31
|
+
* already renders.
|
|
32
|
+
*
|
|
33
|
+
* De-duplicates by `session_id`, keeping first occurrence. A session prompted
|
|
34
|
+
* between two page fetches moves to the top of the `updated_at DESC` order, so
|
|
35
|
+
* a row already served on page 1 legitimately reappears on page 2 — keyset
|
|
36
|
+
* paging makes that a shifted window, not a bug to fix server-side. Rendering
|
|
37
|
+
* it twice would hand React two children with the same key.
|
|
38
|
+
*/
|
|
39
|
+
export function flattenProjectSessionPages(data) {
|
|
40
|
+
if (!data)
|
|
41
|
+
return [];
|
|
42
|
+
const seen = new Set();
|
|
43
|
+
const flat = [];
|
|
44
|
+
for (const page of data.pages) {
|
|
45
|
+
for (const session of page.items) {
|
|
46
|
+
if (seen.has(session.session_id))
|
|
47
|
+
continue;
|
|
48
|
+
seen.add(session.session_id);
|
|
49
|
+
flat.push(session);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return flat;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* One project's sessions, newest activity first, fetched a page at a time.
|
|
56
|
+
*
|
|
57
|
+
* Returns the flat `sessions` array plus the paging controls, so a list that
|
|
58
|
+
* previously read `data ?? []` changes only where the array comes from.
|
|
59
|
+
*/
|
|
60
|
+
export function useProjectSessions(projectId, options) {
|
|
61
|
+
const scope = options?.scope ?? 'visible';
|
|
62
|
+
const query = useInfiniteQuery({
|
|
63
|
+
queryKey: qk.project.sessionsPaged(projectId, scope),
|
|
64
|
+
initialPageParam: null,
|
|
65
|
+
queryFn: ({ pageParam }) => listProjectSessionsPage(projectId, {
|
|
66
|
+
scope,
|
|
67
|
+
limit: options?.limit,
|
|
68
|
+
cursor: pageParam,
|
|
69
|
+
}),
|
|
70
|
+
getNextPageParam: projectSessionsPageParam,
|
|
71
|
+
enabled: options?.enabled ?? true,
|
|
72
|
+
refetchOnWindowFocus: options?.refetchOnWindowFocus,
|
|
73
|
+
refetchInterval: (query) => {
|
|
74
|
+
const interval = options?.refetchInterval;
|
|
75
|
+
if (typeof interval !== 'function')
|
|
76
|
+
return interval ?? false;
|
|
77
|
+
return interval(flattenProjectSessionPages(query.state.data));
|
|
78
|
+
},
|
|
79
|
+
...contract('inventory'),
|
|
80
|
+
});
|
|
81
|
+
return {
|
|
82
|
+
...query,
|
|
83
|
+
/**
|
|
84
|
+
* Every page loaded so far, flattened and de-duplicated.
|
|
85
|
+
*
|
|
86
|
+
* A poll refetches EVERY loaded page, so a viewer who has pressed
|
|
87
|
+
* "Load more" several times pays for each of them on every tick. That is
|
|
88
|
+
* the intended trade — it is bounded by what the viewer actually asked to
|
|
89
|
+
* see, where the old behavior was bounded by nothing.
|
|
90
|
+
*/
|
|
91
|
+
sessions: flattenProjectSessionPages(query.data),
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=use-project-sessions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-project-sessions.js","sourceRoot":"","sources":["../../src/react/use-project-sessions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EACL,uBAAuB,GAIxB,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EAAE,EAAE,EAAE,MAAM,cAAc,CAAC;AAClC,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE7C;;;;;GAKG;AACH,MAAM,UAAU,wBAAwB,CAAC,IAAwB;IAC/D,OAAO,IAAI,CAAC,WAAW,IAAI,SAAS,CAAC;AACvC,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,0BAA0B,CACxC,IAAwE;IAExE,IAAI,CAAC,IAAI;QAAE,OAAO,EAAE,CAAC;IACrB,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAC;IAC/B,MAAM,IAAI,GAAqB,EAAE,CAAC;IAClC,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;QAC9B,KAAK,MAAM,OAAO,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;YACjC,IAAI,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,UAAU,CAAC;gBAAE,SAAS;YAC3C,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;YAC7B,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACrB,CAAC;IACH,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAUD;;;;;GAKG;AACH,MAAM,UAAU,kBAAkB,CAAC,SAAiB,EAAE,OAAmC;IACvF,MAAM,KAAK,GAAG,OAAO,EAAE,KAAK,IAAI,SAAS,CAAC;IAC1C,MAAM,KAAK,GAAG,gBAAgB,CAAC;QAC7B,QAAQ,EAAE,EAAE,CAAC,OAAO,CAAC,aAAa,CAAC,SAAS,EAAE,KAAK,CAAC;QACpD,gBAAgB,EAAE,IAAqB;QACvC,OAAO,EAAE,CAAC,EAAE,SAAS,EAAE,EAAE,EAAE,CACzB,uBAAuB,CAAC,SAAS,EAAE;YACjC,KAAK;YACL,KAAK,EAAE,OAAO,EAAE,KAAK;YACrB,MAAM,EAAE,SAAS;SAClB,CAAC;QACJ,gBAAgB,EAAE,wBAAwB;QAC1C,OAAO,EAAE,OAAO,EAAE,OAAO,IAAI,IAAI;QACjC,oBAAoB,EAAE,OAAO,EAAE,oBAAoB;QACnD,eAAe,EAAE,CAAC,KAAK,EAAE,EAAE;YACzB,MAAM,QAAQ,GAAG,OAAO,EAAE,eAAe,CAAC;YAC1C,IAAI,OAAO,QAAQ,KAAK,UAAU;gBAAE,OAAO,QAAQ,IAAI,KAAK,CAAC;YAC7D,OAAO,QAAQ,CAAC,0BAA0B,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;QAChE,CAAC;QACD,GAAG,QAAQ,CAAC,WAAW,CAAC;KACzB,CAAC,CAAC;IAEH,OAAO;QACL,GAAG,KAAK;QACR;;;;;;;WAOG;QACH,QAAQ,EAAE,0BAA0B,CAAC,KAAK,CAAC,IAAI,CAAC;KACjD,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kortix/sdk",
|
|
3
|
-
"version": "0.13.
|
|
3
|
+
"version": "0.13.20",
|
|
4
4
|
"description": "Official Kortix frontend TypeScript SDK — one typed client for the Kortix agent platform. Unifies project/session lifecycle and live agent streaming behind a single ergonomic Session handle, so web, mobile, and white-label apps never touch the raw HTTP API or OpenCode semantics.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "Elastic-2.0",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
],
|
|
21
21
|
"sideEffects": false,
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@kortix/llm-catalog": "0.13.
|
|
23
|
+
"@kortix/llm-catalog": "0.13.20",
|
|
24
24
|
"@opencode-ai/sdk": "1.18.23",
|
|
25
25
|
"zustand": "^5.0.3"
|
|
26
26
|
},
|