@blocksdiy/blocks-client-sdk 1.14.0 → 1.15.0
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/AgentRef.d.ts +18 -0
- package/dist/AgentRef.d.ts.map +1 -0
- package/dist/AgentRef.js +33 -0
- package/dist/ClientSdk.d.ts +7 -0
- package/dist/ClientSdk.d.ts.map +1 -1
- package/dist/ClientSdk.js +12 -0
- package/dist/Entity.d.ts +42 -2
- package/dist/Entity.d.ts.map +1 -1
- package/dist/Entity.js +20 -0
- package/dist/EntityCache.d.ts +2 -0
- package/dist/EntityCache.d.ts.map +1 -1
- package/dist/EntityCache.js +17 -2
- package/dist/ReactClientSdk.d.ts +63 -1
- package/dist/ReactClientSdk.d.ts.map +1 -1
- package/dist/ReactClientSdk.jsx +76 -1
- package/package.json +3 -3
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { AgentConfig } from "./Agent.js";
|
|
2
|
+
import type { AgentChatConfig } from "./AgentChat.js";
|
|
3
|
+
export declare const isBlockId: (ref: string) => boolean;
|
|
4
|
+
/** The agent a handle refers to: an agent's own `id`, or an agent chat's `agentId`. */
|
|
5
|
+
export declare const agentRefOf: (config: AgentConfig | AgentChatConfig) => string | undefined;
|
|
6
|
+
/**
|
|
7
|
+
* Whether `agentId` (a block id or a name) is the agent `ref` names. `blockId` is `ref` resolved to
|
|
8
|
+
* a block id — `undefined` while that lookup is pending, `null` when there is none — and is only
|
|
9
|
+
* consulted when `ref` is a name.
|
|
10
|
+
*/
|
|
11
|
+
export declare const matchesAgentRef: (agentId: string | null | undefined, ref: string | undefined, blockId?: string | null) => boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Resolves `ref` to the agent's block id: a block id is returned as-is, a name is looked up with
|
|
14
|
+
* `getBlockByName`. `null` when the name matches no agent — the lookup answers a miss with an
|
|
15
|
+
* `{ error }` body rather than a failed response, so anything without a block `id` is a miss.
|
|
16
|
+
*/
|
|
17
|
+
export declare const resolveAgentBlockId: (ref: string, getBlockByName: (name: string) => Promise<unknown>) => Promise<string | null>;
|
|
18
|
+
//# sourceMappingURL=AgentRef.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AgentRef.d.ts","sourceRoot":"","sources":["../src/AgentRef.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAC3C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AASnD,eAAO,MAAM,SAAS,GAAI,KAAK,MAAM,KAAG,OAA4C,CAAC;AAErF,uFAAuF;AACvF,eAAO,MAAM,UAAU,GAAI,QAAQ,WAAW,GAAG,eAAe,KAAG,MAAM,GAAG,SACtB,CAAC;AAEvD;;;;GAIG;AACH,eAAO,MAAM,eAAe,GAC1B,SAAS,MAAM,GAAG,IAAI,GAAG,SAAS,EAClC,KAAK,MAAM,GAAG,SAAS,EACvB,UAAU,MAAM,GAAG,IAAI,KACtB,OAKF,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,GAC9B,KAAK,MAAM,EACX,gBAAgB,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,KACjD,OAAO,CAAC,MAAM,GAAG,IAAI,CAOvB,CAAC"}
|
package/dist/AgentRef.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A Mongo ObjectId or a UUID. Anything else an agent ref holds is the agent's artifact name — what
|
|
3
|
+
* the generated `@/product-types` handles carry — while the platform (a row's `createdByAgentId`,
|
|
4
|
+
* attribution's `updatedByAgentId`) records the agent's block id.
|
|
5
|
+
*/
|
|
6
|
+
const BLOCK_ID_PATTERN = /^(?:[0-9a-f]{24}|[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12})$/i;
|
|
7
|
+
export const isBlockId = (ref) => BLOCK_ID_PATTERN.test(ref.trim());
|
|
8
|
+
/** The agent a handle refers to: an agent's own `id`, or an agent chat's `agentId`. */
|
|
9
|
+
export const agentRefOf = (config) => "agentChatId" in config ? config.agentId : config.id;
|
|
10
|
+
/**
|
|
11
|
+
* Whether `agentId` (a block id or a name) is the agent `ref` names. `blockId` is `ref` resolved to
|
|
12
|
+
* a block id — `undefined` while that lookup is pending, `null` when there is none — and is only
|
|
13
|
+
* consulted when `ref` is a name.
|
|
14
|
+
*/
|
|
15
|
+
export const matchesAgentRef = (agentId, ref, blockId) => {
|
|
16
|
+
if (!agentId || !ref) {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
return agentId === ref || (!!blockId && agentId === blockId);
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Resolves `ref` to the agent's block id: a block id is returned as-is, a name is looked up with
|
|
23
|
+
* `getBlockByName`. `null` when the name matches no agent — the lookup answers a miss with an
|
|
24
|
+
* `{ error }` body rather than a failed response, so anything without a block `id` is a miss.
|
|
25
|
+
*/
|
|
26
|
+
export const resolveAgentBlockId = async (ref, getBlockByName) => {
|
|
27
|
+
if (isBlockId(ref)) {
|
|
28
|
+
return ref;
|
|
29
|
+
}
|
|
30
|
+
const block = await getBlockByName(ref);
|
|
31
|
+
const id = block?.id;
|
|
32
|
+
return typeof id === "string" && isBlockId(id) ? id : null;
|
|
33
|
+
};
|
package/dist/ClientSdk.d.ts
CHANGED
|
@@ -150,6 +150,13 @@ export declare class ClientSdk {
|
|
|
150
150
|
* An Agent represents an app agent generated from product-types.
|
|
151
151
|
*/
|
|
152
152
|
agent<AC extends AgentConfig = AgentConfig>(agentConfig: AC): Agent<AC>;
|
|
153
|
+
/**
|
|
154
|
+
* Resolves an agent ref — a block id, or the name a generated handle carries — to the agent's
|
|
155
|
+
* block id, the value the platform records on rows (`createdByAgentId`) and in attribution
|
|
156
|
+
* (`updatedByAgentId`). `null` when no agent in this app has that name. Resolved against the
|
|
157
|
+
* app version being viewed, so an agent that exists only in a draft resolves there.
|
|
158
|
+
*/
|
|
159
|
+
resolveAgentBlockId(agentRef: string): Promise<string | null>;
|
|
153
160
|
/**
|
|
154
161
|
* Gets or creates an AgentChat instance for the specified agent chat configuration
|
|
155
162
|
*
|
package/dist/ClientSdk.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ClientSdk.d.ts","sourceRoot":"","sources":["../src/ClientSdk.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ClientSdk.d.ts","sourceRoot":"","sources":["../src/ClientSdk.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,MAAM,EAAE,KAAK,YAAY,EAAE,MAAM,UAAU,CAAC;AACrD,OAAO,EAAE,KAAK,EAAE,KAAK,WAAW,EAAE,MAAM,SAAS,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEzD,OAAO,EAAE,MAAM,EAAE,KAAK,YAAY,EAAE,MAAM,UAAU,CAAC;AACrD,OAAO,EAAE,IAAI,EAAE,KAAK,UAAU,EAAE,MAAM,QAAQ,CAAC;AAE/C;;;;;;;;;;;;;GAaG;AACH,MAAM,WAAW,IAAI;IACnB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,OAAO,GAAG,KAAK,CAAC;IAC7B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,eAAe,EAAE,OAAO,CAAC;CAC1B;AAED,MAAM,WAAW,iBAAiB;IAChC,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED;;;;;GAKG;AACH,MAAM,WAAW,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S,eAAe,GAAG,eAAe,EAAE,eAAe,EAAE,GAAG,GAQhB,SAAS,CAAC,GAAG,CAAC;YAG7D,YAAY;IAiCpB,MAAM,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,UAAU,EAAE,EAAE;QAAE,UAAU,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,IAAI,CAAA;KAAE,GAAG,OAAO,CAAC,MAAM,CAAC;IAyCvG;;;;;;;;;;;;;OAaG;IACH,OAAO;IAIP;;;;;;;;;;OAUG;IACG,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,iBAAsB;IAoBlF;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2BG;IACG,aAAa,CAAC,EAAE,KAAK,EAAE,EAAE;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE;IAmBhD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAiCG;IACH,iBAAiB;CAGlB"}
|
package/dist/ClientSdk.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { AppVersionService } from "@blocksdiy/blocks-client-api/appVersionService";
|
|
2
|
+
import { BlocksApiService } from "@blocksdiy/blocks-client-api/blocksStoreService";
|
|
2
3
|
import { getGoogleBaseUrl, getHost } from "@blocksdiy/blocks-client-api/envService";
|
|
3
4
|
import { Action } from "./Action.js";
|
|
4
5
|
import { Agent } from "./Agent.js";
|
|
5
6
|
import { AgentChat } from "./AgentChat.js";
|
|
7
|
+
import { resolveAgentBlockId } from "./AgentRef.js";
|
|
6
8
|
import { Entity } from "./Entity.js";
|
|
7
9
|
import { Page } from "./Page.js";
|
|
8
10
|
/**
|
|
@@ -156,6 +158,16 @@ export class ClientSdk {
|
|
|
156
158
|
}
|
|
157
159
|
return this.agentsMap.get(agentConfig.id);
|
|
158
160
|
}
|
|
161
|
+
/**
|
|
162
|
+
* Resolves an agent ref — a block id, or the name a generated handle carries — to the agent's
|
|
163
|
+
* block id, the value the platform records on rows (`createdByAgentId`) and in attribution
|
|
164
|
+
* (`updatedByAgentId`). `null` when no agent in this app has that name. Resolved against the
|
|
165
|
+
* app version being viewed, so an agent that exists only in a draft resolves there.
|
|
166
|
+
*/
|
|
167
|
+
resolveAgentBlockId(agentRef) {
|
|
168
|
+
const blocksApi = new BlocksApiService({ appId: this.appId, token: this.token });
|
|
169
|
+
return resolveAgentBlockId(agentRef, (name) => blocksApi.getBlock(name, this.appId, "agent", "agent"));
|
|
170
|
+
}
|
|
159
171
|
/**
|
|
160
172
|
* Gets or creates an AgentChat instance for the specified agent chat configuration
|
|
161
173
|
*
|
package/dist/Entity.d.ts
CHANGED
|
@@ -14,8 +14,36 @@ export interface BaseEntityType {
|
|
|
14
14
|
createdBy: string;
|
|
15
15
|
/** ID of the user who last updated the entity */
|
|
16
16
|
updatedBy: string;
|
|
17
|
-
/** ID of the agent that
|
|
18
|
-
|
|
17
|
+
/** ID of the agent that created the entity, when an agent created it */
|
|
18
|
+
createdByAgentId?: string | null;
|
|
19
|
+
/** ID of the agent conversation thread the entity was created in, when an agent created it */
|
|
20
|
+
createdByAgentThreadId?: string | null;
|
|
21
|
+
}
|
|
22
|
+
/** Which agent last wrote one column of an entity. */
|
|
23
|
+
export interface EntityColumnAttribution {
|
|
24
|
+
/** ISO timestamp of when the column was last written */
|
|
25
|
+
lastUpdatedAt?: string;
|
|
26
|
+
/** ID of the agent that last wrote the column, null when a person did */
|
|
27
|
+
updatedByAgentId: string | null;
|
|
28
|
+
/** ID of the agent conversation thread the column was last written in */
|
|
29
|
+
updatedByAgentThreadId: string | null;
|
|
30
|
+
/** ID of the agent run (one agent turn) that last wrote the column */
|
|
31
|
+
updatedByAgentRunId: string | null;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Which agents touched an entity: the agent, thread and run that created it, and per column the
|
|
35
|
+
* agent, thread and run that last wrote it. Columns the current user may not see are left out.
|
|
36
|
+
*/
|
|
37
|
+
export interface EntityAttribution<E extends EntityConfig = EntityConfig> {
|
|
38
|
+
id: string;
|
|
39
|
+
/** ID of the agent that created the entity, null when a person did */
|
|
40
|
+
createdByAgentId: string | null;
|
|
41
|
+
/** ID of the agent conversation thread the entity was created in */
|
|
42
|
+
createdByAgentThreadId: string | null;
|
|
43
|
+
/** ID of the agent run (one agent turn) that created the entity */
|
|
44
|
+
createdByAgentRunId: string | null;
|
|
45
|
+
/** Keyed by entity property name; only columns with recorded writes appear */
|
|
46
|
+
columns: Partial<Record<keyof EntityTypeOnlyMutable<E> & string, EntityColumnAttribution>>;
|
|
19
47
|
}
|
|
20
48
|
/**
|
|
21
49
|
* Configuration for defining an entity type
|
|
@@ -117,6 +145,18 @@ export declare class Entity<EC extends EntityConfig = EntityConfig> {
|
|
|
117
145
|
* ```
|
|
118
146
|
*/
|
|
119
147
|
findMany(filters?: any): Promise<any[]>;
|
|
148
|
+
/**
|
|
149
|
+
* Retrieves which agents created and last changed an entity
|
|
150
|
+
*
|
|
151
|
+
* @param {string} rowId - The entity id
|
|
152
|
+
* @returns {Promise<EntityAttribution<EC> | null>} The attribution, or null when the entity is not visible
|
|
153
|
+
* @example
|
|
154
|
+
* ```ts
|
|
155
|
+
* const attribution = await taskEntity.findAttribution(task.id);
|
|
156
|
+
* attribution?.columns.status?.updatedByAgentRunId; // the agent run that last set the status
|
|
157
|
+
* ```
|
|
158
|
+
*/
|
|
159
|
+
findAttribution(rowId: string): Promise<EntityAttribution<EC> | null>;
|
|
120
160
|
/**
|
|
121
161
|
* Creates a new entity in the database
|
|
122
162
|
*
|
package/dist/Entity.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Entity.d.ts","sourceRoot":"","sources":["../src/Entity.ts"],"names":[],"mappings":"AAaA;;;;GAIG;AACH,MAAM,WAAW,cAAc;IAC7B,uCAAuC;IACvC,EAAE,EAAE,MAAM,CAAC;IACX,mDAAmD;IACnD,SAAS,EAAE,MAAM,CAAC;IAClB,wDAAwD;IACxD,SAAS,EA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;;;;;;;;;;;;;;OAgCG;IACG,UAAU,CAAC,IAAI,EAAE,qBAAqB,CAAC,EAAE,CAAC,EAAE;IAUlD;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACG,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,CAAC,qBAAqB,CAAC,EAAE,CAAC,CAAC;IAUvE;;;;;;;;;;;;;;;OAeG;IACG,SAAS,CAAC,EAAE,EAAE,MAAM;IAS1B;;;;;;;;;;;;;;;;;;OAkBG;IACG,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE;CAS/B"}
|
package/dist/Entity.js
CHANGED
|
@@ -95,6 +95,26 @@ export class Entity {
|
|
|
95
95
|
throw error;
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
|
+
/**
|
|
99
|
+
* Retrieves which agents created and last changed an entity
|
|
100
|
+
*
|
|
101
|
+
* @param {string} rowId - The entity id
|
|
102
|
+
* @returns {Promise<EntityAttribution<EC> | null>} The attribution, or null when the entity is not visible
|
|
103
|
+
* @example
|
|
104
|
+
* ```ts
|
|
105
|
+
* const attribution = await taskEntity.findAttribution(task.id);
|
|
106
|
+
* attribution?.columns.status?.updatedByAgentRunId; // the agent run that last set the status
|
|
107
|
+
* ```
|
|
108
|
+
*/
|
|
109
|
+
async findAttribution(rowId) {
|
|
110
|
+
try {
|
|
111
|
+
return (await this.dataApiService.getRowAttribution(this.tableBlockId, rowId));
|
|
112
|
+
}
|
|
113
|
+
catch (error) {
|
|
114
|
+
console.warn(error);
|
|
115
|
+
return null;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
98
118
|
/**
|
|
99
119
|
* Creates a new entity in the database
|
|
100
120
|
*
|
package/dist/EntityCache.d.ts
CHANGED
|
@@ -36,6 +36,8 @@ export declare const sameId: (a: unknown, b: unknown) => boolean;
|
|
|
36
36
|
* is more trustworthy than an undecidable comparison).
|
|
37
37
|
*/
|
|
38
38
|
export declare const isIncomingRowNewer: (existing: unknown, incoming: EntityCacheRow) => boolean;
|
|
39
|
+
export declare const entityAttributionKey: (tableBlockId: string, rowId: string | number) => QueryKey;
|
|
40
|
+
export declare const isAttributionQueryKey: (queryKey: QueryKey, tableBlockId: string) => boolean;
|
|
39
41
|
export declare const isListQueryKey: (queryKey: QueryKey, tableBlockId: string) => boolean;
|
|
40
42
|
export declare const isUnfilteredListQueryKey: (queryKey: QueryKey, tableBlockId: string) => boolean;
|
|
41
43
|
export declare const isFilteredListQueryKey: (queryKey: QueryKey, tableBlockId: string) => boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EntityCache.d.ts","sourceRoot":"","sources":["../src/EntityCache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,WAAW,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEvE,eAAO,MAAM,kBAAkB,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"EntityCache.d.ts","sourceRoot":"","sources":["../src/EntityCache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,WAAW,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEvE,eAAO,MAAM,kBAAkB,aAAa,CAAC;AAK7C;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,MAAM,GAAG,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,MAAM,WAAW,sBAAsB;IACrC;;;;OAIG;IACH,SAAS,EAAE,QAAQ,EAAE,CAAC;CACvB;AAED,MAAM,MAAM,qBAAqB,GAAG,CAAC,QAAQ,EAAE,OAAO,CAAC,EAAE,CAAC;AAE1D,eAAO,MAAM,cAAc,GAAI,cAAc,MAAM,KAAG,QAA8C,CAAC;AAQrG;;;;;;;GAOG;AACH,eAAO,MAAM,mBAAmB,GAAI,QAAQ,OAAO,KAAG,cAAc,EAMnE,CAAC;AAEF,eAAO,MAAM,MAAM,GAAI,GA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eAAO,MAAM,6BAA6B,GACxC,aAAa,WAAW,EACxB,cAAc,MAAM,EACpB,SAAS,uBAAuB,GAAG,SAAS,EAC5C,uBAA8B;IAAE,gBAAgB,CAAC,EAAE,OAAO,CAAA;CAAO,KAChE,IAaF,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,uBAAuB,GAClC,aAAa,WAAW,EACxB,cAAc,MAAM,EACpB,QAAQ,OAAO,EACf,iDAGG;IAAE,0BAA0B,EAAE,OAAO,CAAC;IAAC,cAAc,CAAC,EAAE,QAAQ,EAAE,CAAA;CAAE,KACtE,OAAO,CAAC,IAAI,CAmBd,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,uBAAuB,GAClC,aAAa,WAAW,EACxB,cAAc,MAAM,EACpB,QAAQ,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,EAC3B,qBAAyB;IAAE,cAAc,CAAC,EAAE,QAAQ,EAAE,CAAA;CAAO,KAC5D,OAAO,CAAC,IAAI,CAad,CAAC"}
|
package/dist/EntityCache.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { hashKey } from "@tanstack/react-query";
|
|
2
2
|
export const ENTITIES_QUERY_KEY = "entities";
|
|
3
3
|
const ONE_SEGMENT = "one";
|
|
4
|
+
const ATTRIBUTION_SEGMENT = "attribution";
|
|
4
5
|
export const entityTableKey = (tableBlockId) => [ENTITIES_QUERY_KEY, tableBlockId];
|
|
5
6
|
const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
6
7
|
const isValidRow = (value) => isRecord(value) && (typeof value.id === "string" || typeof value.id === "number");
|
|
@@ -39,9 +40,18 @@ export const isIncomingRowNewer = (existing, incoming) => {
|
|
|
39
40
|
return incomingTime >= existingTime;
|
|
40
41
|
};
|
|
41
42
|
/* Query key classification.
|
|
42
|
-
* List queries:
|
|
43
|
-
* One queries:
|
|
43
|
+
* List queries: [ENTITIES_QUERY_KEY, tableBlockId, filters?] (length 3, filters may be undefined)
|
|
44
|
+
* One queries: [ENTITIES_QUERY_KEY, tableBlockId, "one", filters] (length 4)
|
|
45
|
+
* Attribution queries: [ENTITIES_QUERY_KEY, tableBlockId, "attribution", rowId] (length 4) — never
|
|
46
|
+
* written to from rows (they hold no row), only invalidated on every write to the table.
|
|
44
47
|
*/
|
|
48
|
+
export const entityAttributionKey = (tableBlockId, rowId) => [
|
|
49
|
+
ENTITIES_QUERY_KEY,
|
|
50
|
+
tableBlockId,
|
|
51
|
+
ATTRIBUTION_SEGMENT,
|
|
52
|
+
String(rowId),
|
|
53
|
+
];
|
|
54
|
+
export const isAttributionQueryKey = (queryKey, tableBlockId) => isTableKey(queryKey, tableBlockId) && queryKey.length === 4 && queryKey[2] === ATTRIBUTION_SEGMENT;
|
|
45
55
|
const isTableKey = (queryKey, tableBlockId) => Array.isArray(queryKey) && queryKey[0] === ENTITIES_QUERY_KEY && queryKey[1] === tableBlockId;
|
|
46
56
|
export const isListQueryKey = (queryKey, tableBlockId) => isTableKey(queryKey, tableBlockId) && queryKey.length === 3 && queryKey[2] !== ONE_SEGMENT;
|
|
47
57
|
export const isUnfilteredListQueryKey = (queryKey, tableBlockId) => isListQueryKey(queryKey, tableBlockId) && queryKey[2] == null;
|
|
@@ -265,6 +275,11 @@ export const invalidateEntityQueriesAfterWrite = (queryClient, tableBlockId, { s
|
|
|
265
275
|
if (staleHashes.has(hashKey(query.queryKey))) {
|
|
266
276
|
return true;
|
|
267
277
|
}
|
|
278
|
+
// Any write may change who last wrote a row's columns, and attribution is never patched
|
|
279
|
+
// from row data — so it is always refetched.
|
|
280
|
+
if (isAttributionQueryKey(query.queryKey, tableBlockId)) {
|
|
281
|
+
return true;
|
|
282
|
+
}
|
|
268
283
|
if (filteredLists && isFilteredListQueryKey(query.queryKey, tableBlockId)) {
|
|
269
284
|
return true;
|
|
270
285
|
}
|
package/dist/ReactClientSdk.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { ActionConfig } from "./Action.js";
|
|
|
2
2
|
import type { AgentConfig } from "./Agent.js";
|
|
3
3
|
import type { AgentChatConfig } from "./AgentChat.js";
|
|
4
4
|
import { ClientSdk, UpdateUserOptions } from "./ClientSdk.js";
|
|
5
|
-
import type { EntityConfig, EntityType, EntityTypeOnlyMutable } from "./Entity.js";
|
|
5
|
+
import type { EntityAttribution, EntityConfig, EntityType, EntityTypeOnlyMutable } from "./Entity.js";
|
|
6
6
|
import type { PageConfig } from "./Page.js";
|
|
7
7
|
export declare class ReactClientSdk extends ClientSdk {
|
|
8
8
|
}
|
|
@@ -173,6 +173,39 @@ export declare const useEntityGetOne: <EC extends EntityConfig = EntityConfig>(e
|
|
|
173
173
|
isSuccess: boolean;
|
|
174
174
|
status: "pending" | "error" | "success";
|
|
175
175
|
};
|
|
176
|
+
/**
|
|
177
|
+
* Hook to fetch which agents created and last changed one entity
|
|
178
|
+
*
|
|
179
|
+
* Returns the agent, thread and run that created the entity, and per property the agent, thread
|
|
180
|
+
* and run that last wrote it. Refetched automatically after any write to the entity's table.
|
|
181
|
+
* Pass `enabled: false` until it is needed (e.g. until a row's menu opens) — it is one request
|
|
182
|
+
* per entity.
|
|
183
|
+
*
|
|
184
|
+
* @template EC - Entity configuration type
|
|
185
|
+
* @param {EC} entityConfig - Configuration for the entity type
|
|
186
|
+
* @param {string | undefined} rowId - The entity id; the query is disabled while it is undefined
|
|
187
|
+
* @param {Object} [queryOptions] - Optional React Query configuration options
|
|
188
|
+
* @param {boolean} [queryOptions.enabled] - Whether the query should automatically execute
|
|
189
|
+
* @example
|
|
190
|
+
* ```tsx
|
|
191
|
+
* import { TaskEntity } from '@/product-types';
|
|
192
|
+
*
|
|
193
|
+
* function TaskMenu({ task, open }) {
|
|
194
|
+
* const { data: attribution } = useEntityAttribution(TaskEntity, task.id, { enabled: open });
|
|
195
|
+
* const statusRunId = attribution?.columns.status?.updatedByAgentRunId;
|
|
196
|
+
* // ...
|
|
197
|
+
* }
|
|
198
|
+
* ```
|
|
199
|
+
*/
|
|
200
|
+
export declare const useEntityAttribution: <EC extends EntityConfig = EntityConfig>(entityConfig: EC, rowId: string | undefined, queryOptions?: {
|
|
201
|
+
enabled?: boolean;
|
|
202
|
+
}) => {
|
|
203
|
+
data: EntityAttribution<EC> | null | undefined;
|
|
204
|
+
isLoading: boolean;
|
|
205
|
+
error: Error | null;
|
|
206
|
+
isError: boolean;
|
|
207
|
+
isSuccess: boolean;
|
|
208
|
+
};
|
|
176
209
|
/**
|
|
177
210
|
* Hook to create a new entity
|
|
178
211
|
*
|
|
@@ -548,6 +581,35 @@ export declare const useAgentChat: <ACC extends AgentChatConfig = AgentChatConfi
|
|
|
548
581
|
* ```
|
|
549
582
|
*/
|
|
550
583
|
export declare const useAgent: <AC extends AgentConfig = AgentConfig>(agentConfig: AC) => import("./Agent.js").Agent<AC>;
|
|
584
|
+
/**
|
|
585
|
+
* Hook to tell whether an agent id recorded by the platform is a given agent.
|
|
586
|
+
*
|
|
587
|
+
* Rows and attribution record the agent's block id (`row.createdByAgentId`,
|
|
588
|
+
* `attribution.columns.<name>.updatedByAgentId`), while the generated handles carry its name —
|
|
589
|
+
* never compare the two directly. `isAgent` accepts either on both sides: pass the agent's handle
|
|
590
|
+
* or its agent chat's handle, then call `isAgent(id)` with any recorded agent id. Resolving the
|
|
591
|
+
* name is one request per agent, cached for the session.
|
|
592
|
+
*
|
|
593
|
+
* `isAgent` returns `false` until the name has resolved — hide agent-only affordances while
|
|
594
|
+
* `isLoading` rather than treating a pending lookup as "a different agent".
|
|
595
|
+
*
|
|
596
|
+
* @param {AgentConfig | AgentChatConfig} agentConfig - A generated agent or agent chat handle
|
|
597
|
+
* @returns {{ isAgent: (agentId?: string | null) => boolean, isLoading: boolean }}
|
|
598
|
+
* @example
|
|
599
|
+
* ```tsx
|
|
600
|
+
* import { useIsAgent } from '@blocksdiy/blocks-client-sdk/reactSdk';
|
|
601
|
+
* import { SupportChatAgentChat } from '@/product-types';
|
|
602
|
+
*
|
|
603
|
+
* function TaskBadge({ task }) {
|
|
604
|
+
* const { isAgent } = useIsAgent(SupportChatAgentChat);
|
|
605
|
+
* return isAgent(task.createdByAgentId) ? <Badge>Created by the assistant</Badge> : null;
|
|
606
|
+
* }
|
|
607
|
+
* ```
|
|
608
|
+
*/
|
|
609
|
+
export declare const useIsAgent: (agentConfig: AgentConfig | AgentChatConfig) => {
|
|
610
|
+
isAgent: (agentId?: string | null) => boolean;
|
|
611
|
+
isLoading: boolean;
|
|
612
|
+
};
|
|
551
613
|
/**
|
|
552
614
|
* Hook to handle file uploads
|
|
553
615
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ReactClientSdk.d.ts","sourceRoot":"","sources":["../src/ReactClientSdk.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ReactClientSdk.d.ts","sourceRoot":"","sources":["../src/ReactClientSdk.tsx"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAC3C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEnD,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAC3D,OAAO,KAAK,EAAE,iBAAiB,EAAE,YAAY,EAAE,UAAU,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAYnG,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAEzC,qBAAa,cAAe,SAAQ,SAAS;CAAG;AAwChD,oBAAY,iBAAiB;IAC3B,eAAe,oBAAoB;IACnC,eAAe,oBAAoB;IACnC,eAAe,oBAAoB;CACpC;AA+ID;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,eAAO,MAAM,cAAc,GAAI,gDAK5B;IACD,MAAM,EAAE,cAAc,CAAC;IACvB,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,SAAS,EAA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;;GAmBG;AACH,eAAO,MAAM,OAAO,kCASnB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,eAAO,MAAM,YAAY,QAAO;IAC9B,SAAS,EAAE,MAAM,GAAG,OAAO,GAAG,QAAQ,CAAC;IACvC,YAAY,EAAE,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,GAAG,QAAQ,KAAK,IAAI,CAAC;CAIhE,CAAC;AACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuDG;AACH,eAAO,MAAM,iBAAiB,GAAI,cAAa;IAAE,OAAO,CAAC,EAAE,iBAAiB,CAAA;CAAO;;gBAWtC,MAAM;cAAQ,MAAM;;;;;CAwBhE,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AACH,eAAO,MAAM,gBAAgB;+BAOP;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE;;;;CAmBtC,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,eAAO,MAAM,cAAc,cAG1B,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,aAAa,GAAI,EAAE,SAAS,UAAU,GAAG,UAAU,EAAE,YAAY,EAAE,2BAS/E,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,UAAU,GAAI,EAAE,SAAS,UAAU,GAAG,UAAU,EAAE,YAAY,EAAE,WAI5E,CAAC"}
|
package/dist/ReactClientSdk.jsx
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
+
import { AppVersionService } from "@blocksdiy/blocks-client-api/appVersionService";
|
|
1
2
|
import { FatalAppError } from "@blocksdiy/blocks-client-api/errors";
|
|
2
3
|
import { useWebsockets, useWebsocketsAppSubscribe } from "@blocksdiy/blocks-client-api/websocketService";
|
|
3
4
|
import { websocketsService } from "@blocksdiy/blocks-client-api/websocketService";
|
|
4
5
|
import { useAiStreamChunks } from "@blocksdiy/react-common/useAiStreamChunks";
|
|
5
6
|
import { QueryClient, QueryClientProvider, useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
|
6
7
|
import { createContext, useCallback, useContext, useEffect, useMemo, useState } from "react";
|
|
8
|
+
import { agentRefOf, isBlockId, matchesAgentRef } from "./AgentRef.js";
|
|
7
9
|
import { ClientSdk } from "./ClientSdk.js";
|
|
8
|
-
import { applyEntityCreateResult, applyEntityDeleteResult, applyEntityRowPatch, applyEntityRowsDeleted, beginEntityOptimisticWrite, ENTITIES_QUERY_KEY, rollbackEntityOptimisticWrite, } from "./EntityCache.js";
|
|
10
|
+
import { applyEntityCreateResult, applyEntityDeleteResult, applyEntityRowPatch, applyEntityRowsDeleted, beginEntityOptimisticWrite, ENTITIES_QUERY_KEY, entityAttributionKey, rollbackEntityOptimisticWrite, } from "./EntityCache.js";
|
|
9
11
|
import { createEntityLiveSync } from "./EntityLiveSync.js";
|
|
10
12
|
export class ReactClientSdk extends ClientSdk {
|
|
11
13
|
}
|
|
@@ -372,6 +374,39 @@ export const useEntityGetOne = (entityConfig, filters, queryOptions = {}) => {
|
|
|
372
374
|
status,
|
|
373
375
|
};
|
|
374
376
|
};
|
|
377
|
+
/**
|
|
378
|
+
* Hook to fetch which agents created and last changed one entity
|
|
379
|
+
*
|
|
380
|
+
* Returns the agent, thread and run that created the entity, and per property the agent, thread
|
|
381
|
+
* and run that last wrote it. Refetched automatically after any write to the entity's table.
|
|
382
|
+
* Pass `enabled: false` until it is needed (e.g. until a row's menu opens) — it is one request
|
|
383
|
+
* per entity.
|
|
384
|
+
*
|
|
385
|
+
* @template EC - Entity configuration type
|
|
386
|
+
* @param {EC} entityConfig - Configuration for the entity type
|
|
387
|
+
* @param {string | undefined} rowId - The entity id; the query is disabled while it is undefined
|
|
388
|
+
* @param {Object} [queryOptions] - Optional React Query configuration options
|
|
389
|
+
* @param {boolean} [queryOptions.enabled] - Whether the query should automatically execute
|
|
390
|
+
* @example
|
|
391
|
+
* ```tsx
|
|
392
|
+
* import { TaskEntity } from '@/product-types';
|
|
393
|
+
*
|
|
394
|
+
* function TaskMenu({ task, open }) {
|
|
395
|
+
* const { data: attribution } = useEntityAttribution(TaskEntity, task.id, { enabled: open });
|
|
396
|
+
* const statusRunId = attribution?.columns.status?.updatedByAgentRunId;
|
|
397
|
+
* // ...
|
|
398
|
+
* }
|
|
399
|
+
* ```
|
|
400
|
+
*/
|
|
401
|
+
export const useEntityAttribution = (entityConfig, rowId, queryOptions = {}) => {
|
|
402
|
+
const client = useClient();
|
|
403
|
+
const { data, isLoading, error, isError, isSuccess } = useQuery({
|
|
404
|
+
queryKey: entityAttributionKey(entityConfig.tableBlockId, rowId ?? ""),
|
|
405
|
+
queryFn: () => client.entity(entityConfig).findAttribution(rowId),
|
|
406
|
+
enabled: rowId !== undefined && rowId !== "" && (queryOptions.enabled ?? true),
|
|
407
|
+
});
|
|
408
|
+
return { data, isLoading, error, isError, isSuccess };
|
|
409
|
+
};
|
|
375
410
|
/**
|
|
376
411
|
* Hook to create a new entity
|
|
377
412
|
*
|
|
@@ -897,6 +932,46 @@ export const useAgent = (agentConfig) => {
|
|
|
897
932
|
const client = useClient();
|
|
898
933
|
return client.agent(agentConfig);
|
|
899
934
|
};
|
|
935
|
+
const AGENT_BLOCK_ID_QUERY_KEY = "agentBlockId";
|
|
936
|
+
/**
|
|
937
|
+
* Hook to tell whether an agent id recorded by the platform is a given agent.
|
|
938
|
+
*
|
|
939
|
+
* Rows and attribution record the agent's block id (`row.createdByAgentId`,
|
|
940
|
+
* `attribution.columns.<name>.updatedByAgentId`), while the generated handles carry its name —
|
|
941
|
+
* never compare the two directly. `isAgent` accepts either on both sides: pass the agent's handle
|
|
942
|
+
* or its agent chat's handle, then call `isAgent(id)` with any recorded agent id. Resolving the
|
|
943
|
+
* name is one request per agent, cached for the session.
|
|
944
|
+
*
|
|
945
|
+
* `isAgent` returns `false` until the name has resolved — hide agent-only affordances while
|
|
946
|
+
* `isLoading` rather than treating a pending lookup as "a different agent".
|
|
947
|
+
*
|
|
948
|
+
* @param {AgentConfig | AgentChatConfig} agentConfig - A generated agent or agent chat handle
|
|
949
|
+
* @returns {{ isAgent: (agentId?: string | null) => boolean, isLoading: boolean }}
|
|
950
|
+
* @example
|
|
951
|
+
* ```tsx
|
|
952
|
+
* import { useIsAgent } from '@blocksdiy/blocks-client-sdk/reactSdk';
|
|
953
|
+
* import { SupportChatAgentChat } from '@/product-types';
|
|
954
|
+
*
|
|
955
|
+
* function TaskBadge({ task }) {
|
|
956
|
+
* const { isAgent } = useIsAgent(SupportChatAgentChat);
|
|
957
|
+
* return isAgent(task.createdByAgentId) ? <Badge>Created by the assistant</Badge> : null;
|
|
958
|
+
* }
|
|
959
|
+
* ```
|
|
960
|
+
*/
|
|
961
|
+
export const useIsAgent = (agentConfig) => {
|
|
962
|
+
const client = useClient();
|
|
963
|
+
const ref = agentRefOf(agentConfig);
|
|
964
|
+
const needsLookup = !!ref && !isBlockId(ref);
|
|
965
|
+
const { data: blockId, isLoading } = useQuery({
|
|
966
|
+
queryKey: [AGENT_BLOCK_ID_QUERY_KEY, client.appId, AppVersionService.getCurrentVersionNumber(client.appId), ref],
|
|
967
|
+
queryFn: () => client.resolveAgentBlockId(ref),
|
|
968
|
+
enabled: needsLookup,
|
|
969
|
+
// An agent's block id never changes, and a name-to-id miss stays a miss for the version.
|
|
970
|
+
staleTime: Infinity,
|
|
971
|
+
});
|
|
972
|
+
const isAgent = useCallback((agentId) => matchesAgentRef(agentId, ref, blockId), [ref, blockId]);
|
|
973
|
+
return { isAgent, isLoading: needsLookup && isLoading };
|
|
974
|
+
};
|
|
900
975
|
/**
|
|
901
976
|
* Hook to handle file uploads
|
|
902
977
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blocksdiy/blocks-client-sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.15.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Blocks client sdk",
|
|
6
6
|
"keywords": [],
|
|
@@ -47,8 +47,8 @@
|
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
49
|
"@tanstack/react-query": "^5.101.0",
|
|
50
|
-
"@blocksdiy/blocks-client-api": "1.
|
|
51
|
-
"@blocksdiy/react-common": "1.
|
|
50
|
+
"@blocksdiy/blocks-client-api": "1.23.0",
|
|
51
|
+
"@blocksdiy/react-common": "1.45.0"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
54
|
"tsc-alias": "^1.8.10",
|