@opengeni/sdk 4.0.2 → 5.0.3-canary.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/README.md +58 -9
- package/dist/artifact-client.d.ts +18 -8
- package/dist/artifacts.js +4 -4
- package/dist/browser.js +2 -2
- package/dist/chat/ids.d.ts +3 -3
- package/dist/chat/index.js +38 -51
- package/dist/chat/index.js.map +1 -1
- package/dist/chat/opengeni.d.ts +10 -12
- package/dist/chat/types.d.ts +7 -3
- package/dist/{chunk-O23OOWJK.js → chunk-4YAL54F3.js} +2 -2
- package/dist/{chunk-UW22XVCT.js → chunk-ARGX7UY4.js} +97 -2
- package/dist/chunk-ARGX7UY4.js.map +1 -0
- package/dist/chunk-J5USCWPE.js +195 -0
- package/dist/chunk-J5USCWPE.js.map +1 -0
- package/dist/{chunk-WNEGCYCE.js → chunk-TARU5CD2.js} +1 -1
- package/dist/chunk-TARU5CD2.js.map +1 -0
- package/dist/{chunk-3IZMCD2K.js → chunk-TOB3B4ZJ.js} +28 -41
- package/dist/chunk-TOB3B4ZJ.js.map +1 -0
- package/dist/{chunk-2H7P45YQ.js → chunk-UQGHX4DI.js} +173 -7
- package/dist/chunk-UQGHX4DI.js.map +1 -0
- package/dist/client.d.ts +39 -4
- package/dist/core.js +3 -3
- package/dist/document-authority.js +3 -3
- package/dist/editable-artifacts.js +1 -1
- package/dist/embedding-client.d.ts +72 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.js +13 -8
- package/dist/index.js.map +1 -1
- package/dist/site-tool-bridge.d.ts +39 -0
- package/dist/site.d.ts +2 -0
- package/dist/site.js +7 -3
- package/dist/types.d.ts +23 -12
- package/package.json +3 -2
- package/src/artifact-client.ts +38 -63
- package/src/chat/ids.ts +3 -3
- package/src/chat/opengeni.ts +41 -57
- package/src/chat/types.ts +7 -3
- package/src/client.ts +253 -12
- package/src/embedding-client.ts +308 -0
- package/src/index.ts +16 -1
- package/src/site-tool-bridge.ts +141 -0
- package/src/site.ts +7 -0
- package/src/types.ts +18 -6
- package/dist/chunk-2H7P45YQ.js.map +0 -1
- package/dist/chunk-3IZMCD2K.js.map +0 -1
- package/dist/chunk-UW22XVCT.js.map +0 -1
- package/dist/chunk-WNEGCYCE.js.map +0 -1
- /package/dist/{chunk-O23OOWJK.js.map → chunk-4YAL54F3.js.map} +0 -0
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { OpenGeniApiError } from "./errors";
|
|
2
|
+
import { siteSessionPath, type SiteHttpRequest } from "./site-http";
|
|
3
|
+
import type { OpenGeniSiteToolCatalog } from "./site";
|
|
4
|
+
import type { OpenGeniWorkspaceTools } from "./tools";
|
|
5
|
+
import type { ToolGatewayCallRequest, ToolGatewayCallResponse, ToolGatewayIdentity } from "./types";
|
|
6
|
+
|
|
7
|
+
export type SiteToolCallRequest = ToolGatewayCallRequest & {
|
|
8
|
+
siteArtifactId: string;
|
|
9
|
+
siteVersionId: string;
|
|
10
|
+
};
|
|
11
|
+
export type SiteToolCaller = (input: {
|
|
12
|
+
workspaceId: string;
|
|
13
|
+
request: SiteToolCallRequest;
|
|
14
|
+
signal: AbortSignal;
|
|
15
|
+
}) => Promise<ToolGatewayCallResponse>;
|
|
16
|
+
export type SiteToolBridge = {
|
|
17
|
+
fetch?: (request: SiteHttpRequest, signal: AbortSignal) => Promise<Response>;
|
|
18
|
+
catalog: (options: { signal: AbortSignal }) => Promise<OpenGeniSiteToolCatalog>;
|
|
19
|
+
call: (
|
|
20
|
+
request: ToolGatewayCallRequest,
|
|
21
|
+
options: { signal: AbortSignal },
|
|
22
|
+
) => Promise<ToolGatewayCallResponse>;
|
|
23
|
+
};
|
|
24
|
+
export type CreateSiteToolBridgeOptions = {
|
|
25
|
+
workspaceTools: Pick<OpenGeniWorkspaceTools, "$catalog">;
|
|
26
|
+
workspaceId: string;
|
|
27
|
+
artifactId: string;
|
|
28
|
+
siteVersionId: string;
|
|
29
|
+
requestedTools: readonly ToolGatewayIdentity[];
|
|
30
|
+
callTool: SiteToolCaller;
|
|
31
|
+
isCatalogStale?: (error: unknown) => boolean;
|
|
32
|
+
/** Optional authenticated host transport for the host-bound workspace API.
|
|
33
|
+
* Omit to expose tools only. Site-provided authorization headers are never forwarded. */
|
|
34
|
+
fetchResponse?: (path: string, init: RequestInit) => Promise<Response>;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
/** Host-side bridge for the opaque Site frame. Supply an authenticated transport;
|
|
38
|
+
* the server independently checks live viewer access and the exact Site version.
|
|
39
|
+
* Recreate on actor/version change. Never take these pinned fields from HTML. */
|
|
40
|
+
export function createSiteToolBridge(input: CreateSiteToolBridgeOptions): SiteToolBridge {
|
|
41
|
+
const allowed = new Set(input.requestedTools.map(identityKey));
|
|
42
|
+
let projectedCatalog: OpenGeniSiteToolCatalog | null = null;
|
|
43
|
+
const loadCatalog = async ({
|
|
44
|
+
signal,
|
|
45
|
+
refresh = false,
|
|
46
|
+
}: {
|
|
47
|
+
signal: AbortSignal;
|
|
48
|
+
refresh?: boolean;
|
|
49
|
+
}): Promise<OpenGeniSiteToolCatalog> => {
|
|
50
|
+
signal.throwIfAborted();
|
|
51
|
+
if (projectedCatalog && !refresh) return projectedCatalog;
|
|
52
|
+
const current = await input.workspaceTools.$catalog({
|
|
53
|
+
signal,
|
|
54
|
+
...(refresh ? { refresh } : {}),
|
|
55
|
+
});
|
|
56
|
+
signal.throwIfAborted();
|
|
57
|
+
if (current.workspaceId !== input.workspaceId)
|
|
58
|
+
throw new Error("Site catalog workspace mismatch");
|
|
59
|
+
projectedCatalog = {
|
|
60
|
+
version: current.version,
|
|
61
|
+
generation: current.generation,
|
|
62
|
+
digest: current.digest,
|
|
63
|
+
createdAt: current.createdAt,
|
|
64
|
+
entries: current.entries.filter((entry) => allowed.has(identityKey(entry.identity))),
|
|
65
|
+
};
|
|
66
|
+
return projectedCatalog;
|
|
67
|
+
};
|
|
68
|
+
return {
|
|
69
|
+
...(input.fetchResponse
|
|
70
|
+
? {
|
|
71
|
+
fetch: async (message: SiteHttpRequest, signal: AbortSignal) => {
|
|
72
|
+
const path = siteSessionPath(
|
|
73
|
+
message.path,
|
|
74
|
+
input.workspaceId,
|
|
75
|
+
message.method,
|
|
76
|
+
input.artifactId,
|
|
77
|
+
);
|
|
78
|
+
const headers = new Headers();
|
|
79
|
+
headers.set("x-opengeni-site-id", input.artifactId);
|
|
80
|
+
headers.set("x-opengeni-site-version", input.siteVersionId);
|
|
81
|
+
for (const [name, value] of message.headers) {
|
|
82
|
+
if (["content-type", "accept", "last-event-id"].includes(name.toLowerCase()))
|
|
83
|
+
headers.set(name, value);
|
|
84
|
+
}
|
|
85
|
+
return input.fetchResponse!(path, {
|
|
86
|
+
method: message.method,
|
|
87
|
+
signal,
|
|
88
|
+
headers: Object.fromEntries(headers),
|
|
89
|
+
...(message.body === undefined ? {} : { body: message.body }),
|
|
90
|
+
});
|
|
91
|
+
},
|
|
92
|
+
}
|
|
93
|
+
: {}),
|
|
94
|
+
catalog: loadCatalog,
|
|
95
|
+
call: async (request, { signal }) => {
|
|
96
|
+
if (!allowed.has(identityKey(request.identity)))
|
|
97
|
+
throw new Error("This tool is not available to the Site");
|
|
98
|
+
const call = async (refresh = false) => {
|
|
99
|
+
const catalog = await loadCatalog({ signal, refresh });
|
|
100
|
+
if (
|
|
101
|
+
!catalog.entries.some(
|
|
102
|
+
(entry) => identityKey(entry.identity) === identityKey(request.identity),
|
|
103
|
+
)
|
|
104
|
+
)
|
|
105
|
+
throw new Error("This requested tool is not enabled in the workspace");
|
|
106
|
+
return input.callTool({
|
|
107
|
+
workspaceId: input.workspaceId,
|
|
108
|
+
signal,
|
|
109
|
+
request: {
|
|
110
|
+
...(request.operationId ? { operationId: request.operationId } : {}),
|
|
111
|
+
catalogDigest: catalog.digest,
|
|
112
|
+
identity: request.identity,
|
|
113
|
+
arguments: request.arguments,
|
|
114
|
+
siteArtifactId: input.artifactId,
|
|
115
|
+
siteVersionId: input.siteVersionId,
|
|
116
|
+
},
|
|
117
|
+
});
|
|
118
|
+
};
|
|
119
|
+
try {
|
|
120
|
+
return await call();
|
|
121
|
+
} catch (error) {
|
|
122
|
+
// Only pre-execution catalog rejection permits one retry. Never retry
|
|
123
|
+
// transport failures, expired credentials or uncertain tool effects.
|
|
124
|
+
if (!(input.isCatalogStale ?? isSiteCatalogStaleError)(error)) throw error;
|
|
125
|
+
projectedCatalog = null;
|
|
126
|
+
return await call(true);
|
|
127
|
+
}
|
|
128
|
+
},
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export function isSiteCatalogStaleError(error: unknown): boolean {
|
|
133
|
+
return (
|
|
134
|
+
error instanceof OpenGeniApiError &&
|
|
135
|
+
error.status === 409 &&
|
|
136
|
+
error.details?.code === "catalog_stale"
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
function identityKey(identity: ToolGatewayIdentity): string {
|
|
140
|
+
return `${identity.serverId}\u0000${identity.toolName}`;
|
|
141
|
+
}
|
package/src/site.ts
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
export { createSiteToolBridge, isSiteCatalogStaleError } from "./site-tool-bridge";
|
|
2
|
+
export type {
|
|
3
|
+
SiteToolBridge,
|
|
4
|
+
SiteToolCaller,
|
|
5
|
+
SiteToolCallRequest,
|
|
6
|
+
CreateSiteToolBridgeOptions,
|
|
7
|
+
} from "./site-tool-bridge";
|
|
1
8
|
import {
|
|
2
9
|
OpenGeniToolsClient,
|
|
3
10
|
type OpenGeniToolTransport,
|
package/src/types.ts
CHANGED
|
@@ -694,6 +694,7 @@ export type McpConnectionAuthoritySelection = {
|
|
|
694
694
|
export type McpServerConnectionRef = {
|
|
695
695
|
connectionId?: string | undefined;
|
|
696
696
|
authoritySource?: "host" | undefined;
|
|
697
|
+
hostBinding?: { bindingId: string; generation: number } | undefined;
|
|
697
698
|
provider?: string | undefined;
|
|
698
699
|
providerDomain: string;
|
|
699
700
|
kind?: ConnectionKind | undefined;
|
|
@@ -879,6 +880,7 @@ export type FikenInstallRequest = {
|
|
|
879
880
|
};
|
|
880
881
|
|
|
881
882
|
export type FikenOAuthStartRequest = {
|
|
883
|
+
returnPath?: string | undefined;
|
|
882
884
|
/** Existing Fiken connection to re-authorize in place (reconnect). */
|
|
883
885
|
connectionId?: string | undefined;
|
|
884
886
|
};
|
|
@@ -1177,6 +1179,8 @@ export type OAuthStartRequest = {
|
|
|
1177
1179
|
resource?: string | undefined;
|
|
1178
1180
|
requestedScopes?: string[] | undefined;
|
|
1179
1181
|
returnPath?: string | undefined;
|
|
1182
|
+
/** Exact trusted-host destination; requires verified external-user mode. */
|
|
1183
|
+
returnUrl?: string | undefined;
|
|
1180
1184
|
connectionId?: string | undefined;
|
|
1181
1185
|
ownership?: ConnectionOwnership | undefined;
|
|
1182
1186
|
oauthClient?:
|
|
@@ -1472,7 +1476,7 @@ export type Session = {
|
|
|
1472
1476
|
/** Agent access scope; absent on servers before the agent-access release. */
|
|
1473
1477
|
agentAccess?: SessionAgentAccess | undefined;
|
|
1474
1478
|
/** Opaque end-user label; null when the session carries none. */
|
|
1475
|
-
|
|
1479
|
+
scopeSubjectId?: SessionScopeSubjectId | null | undefined;
|
|
1476
1480
|
/** Memory scope; absent on servers before the agent-access release. */
|
|
1477
1481
|
memoryScope?: SessionMemoryScope | undefined;
|
|
1478
1482
|
createdAt: string;
|
|
@@ -2857,6 +2861,10 @@ export type ScheduledTask = {
|
|
|
2857
2861
|
};
|
|
2858
2862
|
|
|
2859
2863
|
export type CreateSessionRequest = {
|
|
2864
|
+
/** Opt-in host grants for a direct external-user initial turn. */
|
|
2865
|
+
selectedHostMcpDelegations?:
|
|
2866
|
+
| { serverId: string; delegationId: string; generation: number }[]
|
|
2867
|
+
| undefined;
|
|
2860
2868
|
/** Omitted: defaults/inheritance; []: no bundled guidance. Children cannot widen. */
|
|
2861
2869
|
bundledSkillIds?: BundledSkillId[] | undefined;
|
|
2862
2870
|
// Optional UUID preallocated by an embedding host so it can durably link its
|
|
@@ -2929,14 +2937,15 @@ export type CreateSessionRequest = {
|
|
|
2929
2937
|
// on the platform (the chat facade defaults to "session").
|
|
2930
2938
|
agentAccess?: SessionAgentAccess | undefined;
|
|
2931
2939
|
/** Opaque end-user label inside the workspace. Not a subject, not authority. */
|
|
2932
|
-
|
|
2933
|
-
|
|
2940
|
+
/** Select identity with server-side asUser(), not session creation data. */
|
|
2941
|
+
scopeSubjectId?: never;
|
|
2942
|
+
/** Which Memory the agent reads and where it saves; "user" requires `scopeSubjectId`. */
|
|
2934
2943
|
memoryScope?: SessionMemoryScope | undefined;
|
|
2935
2944
|
};
|
|
2936
2945
|
|
|
2937
2946
|
export type SessionAgentAccess = "session" | "user" | "workspace";
|
|
2938
|
-
export type
|
|
2939
|
-
export type SessionMemoryScope = "workspace" | "user" | "
|
|
2947
|
+
export type SessionScopeSubjectId = string;
|
|
2948
|
+
export type SessionMemoryScope = "workspace" | "user" | "off";
|
|
2940
2949
|
|
|
2941
2950
|
// --- Access, workspaces, API keys -------------------------------------------
|
|
2942
2951
|
|
|
@@ -4610,7 +4619,7 @@ export type ListOrganizationSessionsOptions = {
|
|
|
4610
4619
|
/** `nextCursor` from the previous page. */
|
|
4611
4620
|
cursor?: string | undefined;
|
|
4612
4621
|
/** Keep only sessions labelled with this exact end user. */
|
|
4613
|
-
|
|
4622
|
+
scopeSubjectId?: string | undefined;
|
|
4614
4623
|
/** Keep only sessions in this exact lifecycle state. */
|
|
4615
4624
|
status?: SessionStatus | undefined;
|
|
4616
4625
|
signal?: AbortSignal | undefined;
|
|
@@ -5222,6 +5231,7 @@ export type CreateAgentScheduledTaskRequest = {
|
|
|
5222
5231
|
runMode?: ScheduledTaskRunMode | undefined;
|
|
5223
5232
|
targetSessionId?: string | null | undefined;
|
|
5224
5233
|
connectionAuthorities?: McpConnectionAuthoritySelection[] | undefined;
|
|
5234
|
+
selectedHostMcpDelegations?: CreateSessionRequest["selectedHostMcpDelegations"];
|
|
5225
5235
|
overlapPolicy?: ScheduledTaskOverlapPolicy | undefined;
|
|
5226
5236
|
agentConfig: ScheduledTaskAgentConfigInput;
|
|
5227
5237
|
status?: ScheduledTaskStatus | undefined;
|
|
@@ -5252,6 +5262,7 @@ export type UpdateScheduledTaskRequest = {
|
|
|
5252
5262
|
runMode?: ScheduledTaskRunMode | undefined;
|
|
5253
5263
|
targetSessionId?: string | null | undefined;
|
|
5254
5264
|
connectionAuthorities?: McpConnectionAuthoritySelection[] | undefined;
|
|
5265
|
+
selectedHostMcpDelegations?: CreateSessionRequest["selectedHostMcpDelegations"];
|
|
5255
5266
|
overlapPolicy?: ScheduledTaskOverlapPolicy | undefined;
|
|
5256
5267
|
action?: ScheduledTaskAction | undefined;
|
|
5257
5268
|
agentConfig?: ScheduledTaskAgentConfigInput | undefined;
|
|
@@ -7925,6 +7936,7 @@ export type UserMessageEventInput = {
|
|
|
7925
7936
|
expectedDraftRevision?: number | undefined;
|
|
7926
7937
|
mcpCredentialUpdates?: SessionMcpCredentialUpdateInput[] | undefined;
|
|
7927
7938
|
connectionAuthorities?: McpConnectionAuthoritySelection[] | undefined;
|
|
7939
|
+
selectedHostMcpDelegations?: CreateSessionRequest["selectedHostMcpDelegations"];
|
|
7928
7940
|
personalResourceAttachment?: PersonalResourceAttachmentIntent | undefined;
|
|
7929
7941
|
};
|
|
7930
7942
|
};
|