@opengeni/sdk 4.0.2 → 5.0.0-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
package/README.md
CHANGED
|
@@ -1,5 +1,52 @@
|
|
|
1
1
|
# @opengeni/sdk
|
|
2
2
|
|
|
3
|
+
## External-user admission (implementation branch)
|
|
4
|
+
|
|
5
|
+
On a product backend, `client.asUser(externalId, { source? })` returns a separate
|
|
6
|
+
client that sends the external actor assertion with the organization key. IDs
|
|
7
|
+
are opaque and case-sensitive; the default source is `default`. Keep the key and
|
|
8
|
+
this client server-side. Each request requires the intersection of the key's
|
|
9
|
+
permissions and the user's explicit workspace membership. API-key rotation does
|
|
10
|
+
not change the external identity.
|
|
11
|
+
|
|
12
|
+
Use the service client—not an `asUser` client—to call
|
|
13
|
+
`addExternalWorkspaceMember(workspaceId, { identity: { externalId, source? }, permissions })`
|
|
14
|
+
for explicit onboarding. It requires `members:manage`, cannot grant more than
|
|
15
|
+
the key permits, excludes Personal workspaces, and refuses to overwrite an
|
|
16
|
+
existing membership with different permissions. Ordinary `asUser` calls never
|
|
17
|
+
restore removed workspace membership or reactivate disabled identities.
|
|
18
|
+
|
|
19
|
+
Service `removeWorkspaceMember` supports external members through the existing
|
|
20
|
+
fenced workspace teardown. Account-wide `updateExternalIdentityMembership(
|
|
21
|
+
organizationId, organizationMembershipId, { kind, expectedAuthorizationRevision,
|
|
22
|
+
operationId, reason? })` requires explicit `account:admin` and supports suspend,
|
|
23
|
+
reactivate, and offboard. The membership ID is returned by onboarding; its initial
|
|
24
|
+
authorization revision is 1. Retain the returned revision for subsequent changes.
|
|
25
|
+
Reactivation restores admission, not revoked memberships or work. Offboarding
|
|
26
|
+
follows existing retention policy and cannot be reactivated through this API.
|
|
27
|
+
Native-user targets and `asUser` calls are rejected by this service endpoint.
|
|
28
|
+
|
|
29
|
+
An `asUser` client can discover/access its own provisioned Personal workspace
|
|
30
|
+
under the key's permission ceiling. Core private session operations retain
|
|
31
|
+
organization readiness/settings and explicit sharing acknowledgments; service
|
|
32
|
+
clients gain no Personal-workspace fallback.
|
|
33
|
+
|
|
34
|
+
Optional native-account delegation uses `beginIdentityLink`, authenticated native
|
|
35
|
+
`previewIdentityLink`/`confirmIdentityLink`, and explicit server-side
|
|
36
|
+
`asLinkedUser(externalId, { source?, linkId, expectedLinkRevision })`. Confirmation
|
|
37
|
+
requires the actual native login plus the one-time host challenge; an organization
|
|
38
|
+
key cannot confirm for the native user. `listIdentityLinks(workspaceId, cursor?)`
|
|
39
|
+
returns only the effective participant's links in that organization (50 per page).
|
|
40
|
+
`revokeIdentityLink` requires the observed revision. Linking never changes ordinary
|
|
41
|
+
`asUser`, merges histories or transfers credentials. Link-dependent accepted work
|
|
42
|
+
retains revocation checks across schedules and children. Short-lived inline MCP
|
|
43
|
+
credentials remain supported, and durable renewal stays opt-in.
|
|
44
|
+
|
|
45
|
+
Connect accepts an optional `installationTarget: { instanceKey, displayName,
|
|
46
|
+
expectedInstanceVersion? }`. Keep the exact observed version for an existing named
|
|
47
|
+
account. Setup freezes the target through callback and operation review; omitting
|
|
48
|
+
it creates an independent named account instead of overwriting a default instance.
|
|
49
|
+
|
|
3
50
|
Framework-agnostic TypeScript SDK for the OpenGeni public API: a typed client,
|
|
4
51
|
session lifecycle, and the streaming core — SSE event streaming with automatic
|
|
5
52
|
reconnect, resume-by-sequence, gap backfill, and duplicate suppression — plus
|
|
@@ -36,10 +83,10 @@ const og = new OpenGeni({
|
|
|
36
83
|
|
|
37
84
|
const chat = await og.chat({
|
|
38
85
|
tenant: "acme", // one workspace per customer, created on first use
|
|
39
|
-
user: "u_42", //
|
|
40
|
-
conversation: "c_9", // stable id,
|
|
86
|
+
user: "u_42", // authenticated product user; onboard workspace membership first
|
|
87
|
+
conversation: "c_9", // stable conversation id, independent of the acting user
|
|
41
88
|
agentAccess: "session", // "session" (default) | "user" | "workspace"
|
|
42
|
-
memory: "user", // "
|
|
89
|
+
memory: "user", // "user" | "workspace" | false; session-only agent reach defaults to false
|
|
43
90
|
create: { sandboxBackend: "none" }, // raw create-request passthrough for a pure chat
|
|
44
91
|
});
|
|
45
92
|
|
|
@@ -54,7 +101,7 @@ for await (const chunk of chat.stream("and then?")) {
|
|
|
54
101
|
// Your endpoint. `resolve` is your auth hook: identity comes from the request
|
|
55
102
|
// you authenticated, never from the body. The handler reads the client's
|
|
56
103
|
// conversation id itself (x-opengeni-conversation header, or the wire format's
|
|
57
|
-
// own field) and
|
|
104
|
+
// own field) and authorizes as `user`; return `conversation` from resolve only
|
|
58
105
|
// when the host names it, which is required when there is no `user`.
|
|
59
106
|
export const handler = createChatHandler(og, {
|
|
60
107
|
resolve: async (request) => {
|
|
@@ -69,9 +116,11 @@ export const GET = handler; // conversation history, for restoring the chat on r
|
|
|
69
116
|
export const POST = handler; // send a message, or answer a pending request at .../respond
|
|
70
117
|
```
|
|
71
118
|
|
|
72
|
-
Conversation
|
|
73
|
-
|
|
74
|
-
|
|
119
|
+
Conversation IDs do not change with the acting user. Authorized collaborators
|
|
120
|
+
can use the same session; private visibility prevents access by other users.
|
|
121
|
+
Use `chatBySessionId` for existing and legacy user-namespaced conversations.
|
|
122
|
+
User mode requires explicit workspace membership and never restores removed
|
|
123
|
+
membership automatically. Without a `user`, the host must name the conversation
|
|
75
124
|
from `resolve`. The Vercel and OpenAI adapters send only the latest user
|
|
76
125
|
message; the earlier messages in that request are imported once, as context on
|
|
77
126
|
the first message of a conversation, after which OpenGeni owns the history.
|
|
@@ -82,7 +131,7 @@ shares the customer's documents, instructions, and integrations:
|
|
|
82
131
|
|
|
83
132
|
| Scenario | `agentAccess` | `memory` |
|
|
84
133
|
| ------------------------------------------------- | ------------- | ------------- |
|
|
85
|
-
|
|
|
134
|
+
| Agent confined to its chat tree (support desk) | `"session"` | `false` |
|
|
86
135
|
| One user's chats see each other, not other users' | `"user"` | `"user"` |
|
|
87
136
|
| Everything in the tenant shared | `"workspace"` | `"workspace"` |
|
|
88
137
|
| Shared agent access, no memory | any | `false` |
|
|
@@ -155,7 +204,7 @@ manager. `createOrganizationApiKey(organizationId, { name, access: "read" })`
|
|
|
155
204
|
mints a read-only master key: it inventories shared workspaces and reads their
|
|
156
205
|
sessions, events, and files, but cannot create sessions, send messages, or mint
|
|
157
206
|
keys, and every key reports its tier as `apiKey.access`. Either tier can call
|
|
158
|
-
`listOrganizationSessions(organizationId, { limit, cursor,
|
|
207
|
+
`listOrganizationSessions(organizationId, { limit, cursor, scopeSubjectId, status })`
|
|
159
208
|
for one page of sessions across every shared workspace (each row carries its
|
|
160
209
|
`workspaceId`; private sessions and Personal workspaces never appear), or
|
|
161
210
|
`iterateOrganizationSessions` to follow `nextCursor` to the end.
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { OpenGeniDocumentAuthorityClient } from "./document-authority-client.js";
|
|
2
2
|
import type { FetchResponse } from "./client.js";
|
|
3
|
+
import type { SiteToolCallRequest } from "./site-tool-bridge.js";
|
|
4
|
+
import type { ToolGatewayCallResponse } from "./types.js";
|
|
5
|
+
import type { CreateWorkspaceArtifactRequest, PublishWorkspaceArtifactVersionRequest, WorkspaceArtifactContentResponse, WorkspaceArtifactMutationResponse } from "./workspace-artifacts.js";
|
|
3
6
|
import type { CreateEditableArtifactMaterializationRequest, CreateEditableArtifactResourceRequest, EditableArtifactListResource, EditableArtifactMaterializationJobResource, EditableArtifactPinnedVersionResource, EditableArtifactResource, ImportEditableArtifactResourceRequest, ListSessionEditableArtifactResourcesOptions, PinEditableArtifactVersionRequest, ReadEditableArtifactMaterializationOptions, ReadEditableArtifactResourceOptions } from "./editable-artifact-resources.js";
|
|
4
|
-
import type { CreateWorkspaceArtifactRequest, PublishWorkspaceArtifactVersionRequest, RollbackWorkspaceArtifactRequest, SetWorkspaceArtifactStatusRequest, WorkspaceArtifactContentResponse, WorkspaceArtifactDetailResponse, WorkspaceArtifactListOptions, WorkspaceArtifactListResponse, WorkspaceArtifactMutationResponse } from "./workspace-artifacts.js";
|
|
5
7
|
/** Public SDK client. Optional operator and artifact operations stay out of the console core. */
|
|
6
8
|
export declare class OpenGeniClient extends OpenGeniDocumentAuthorityClient {
|
|
7
9
|
createEditableArtifact(workspaceId: string, request: CreateEditableArtifactResourceRequest, options?: Readonly<{
|
|
@@ -21,11 +23,19 @@ export declare class OpenGeniClient extends OpenGeniDocumentAuthorityClient {
|
|
|
21
23
|
getEditableArtifactMaterialization(workspaceId: string, artifactId: string, jobId: string, options: ReadEditableArtifactMaterializationOptions): Promise<EditableArtifactMaterializationJobResource>;
|
|
22
24
|
/** The caller owns the returned bounded response stream. */
|
|
23
25
|
downloadEditableArtifactMaterialization(workspaceId: string, artifactId: string, jobId: string, options: ReadEditableArtifactMaterializationOptions): Promise<FetchResponse>;
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
26
|
+
/** Exact Site-version gateway call. Keep this client on the authenticated host;
|
|
27
|
+
* the API enforces live viewer access and the version's declared tool allowlist. */
|
|
28
|
+
callWorkspaceSiteTool(workspaceId: string, request: SiteToolCallRequest, options?: {
|
|
29
|
+
signal?: AbortSignal;
|
|
30
|
+
}): Promise<ToolGatewayCallResponse>;
|
|
31
|
+
getWorkspaceArtifactContent(workspaceId: string, artifactId: string, versionOrOptions?: string | {
|
|
32
|
+
versionId?: string;
|
|
33
|
+
signal?: AbortSignal;
|
|
34
|
+
}): Promise<WorkspaceArtifactContentResponse>;
|
|
35
|
+
createWorkspaceArtifact(workspaceId: string, request: CreateWorkspaceArtifactRequest, options?: {
|
|
36
|
+
signal?: AbortSignal;
|
|
37
|
+
}): Promise<WorkspaceArtifactMutationResponse>;
|
|
38
|
+
publishWorkspaceArtifactVersion(workspaceId: string, artifactId: string, request: PublishWorkspaceArtifactVersionRequest, options?: {
|
|
39
|
+
signal?: AbortSignal;
|
|
40
|
+
}): Promise<WorkspaceArtifactMutationResponse>;
|
|
31
41
|
}
|
package/dist/artifacts.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
OpenGeniClient
|
|
3
|
-
} from "./chunk-
|
|
4
|
-
import "./chunk-
|
|
5
|
-
import "./chunk-
|
|
3
|
+
} from "./chunk-TOB3B4ZJ.js";
|
|
4
|
+
import "./chunk-4YAL54F3.js";
|
|
5
|
+
import "./chunk-UQGHX4DI.js";
|
|
6
6
|
import "./chunk-QTBAMHEF.js";
|
|
7
|
-
import "./chunk-
|
|
7
|
+
import "./chunk-TARU5CD2.js";
|
|
8
8
|
import "./chunk-OO5LPTO7.js";
|
|
9
9
|
export {
|
|
10
10
|
OpenGeniClient
|
package/dist/browser.js
CHANGED
|
@@ -8,12 +8,12 @@ import {
|
|
|
8
8
|
} from "./chunk-FMLDFJ2Q.js";
|
|
9
9
|
import {
|
|
10
10
|
OpenGeniClient
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-UQGHX4DI.js";
|
|
12
12
|
import "./chunk-QTBAMHEF.js";
|
|
13
13
|
import {
|
|
14
14
|
OPENGENI_API_CONTRACT_HEADER,
|
|
15
15
|
OPENGENI_API_CONTRACT_REVISION
|
|
16
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-TARU5CD2.js";
|
|
17
17
|
import {
|
|
18
18
|
OpenGeniApiContractMismatchError,
|
|
19
19
|
OpenGeniApiError,
|
package/dist/chat/ids.d.ts
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
* Deterministic chat identities. A conversation id maps to exactly one
|
|
3
3
|
* session id per workspace, so any process can address the same session
|
|
4
4
|
* without storing a mapping, and a double-submitted create collapses through
|
|
5
|
-
* the idempotency key.
|
|
6
|
-
*
|
|
7
|
-
*
|
|
5
|
+
* the idempotency key. The optional legacy label argument is retained only to
|
|
6
|
+
* reproduce historical addresses. New chat calls do not use it: authorization
|
|
7
|
+
* is independent of addressing, so collaborators can share a conversation.
|
|
8
8
|
*/
|
|
9
9
|
/** The end-user label a conversation is namespaced to: the product `source` plus the opaque user id. */
|
|
10
10
|
export type ChatUserLabel = {
|
package/dist/chat/index.js
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
2
|
+
OpenGeniEmbeddingClient
|
|
3
|
+
} from "../chunk-J5USCWPE.js";
|
|
4
|
+
import "../chunk-TOB3B4ZJ.js";
|
|
5
|
+
import "../chunk-4YAL54F3.js";
|
|
6
|
+
import {
|
|
3
7
|
parseSseStream
|
|
4
|
-
} from "../chunk-
|
|
8
|
+
} from "../chunk-UQGHX4DI.js";
|
|
5
9
|
import "../chunk-QTBAMHEF.js";
|
|
6
|
-
import "../chunk-
|
|
10
|
+
import "../chunk-TARU5CD2.js";
|
|
7
11
|
import {
|
|
8
12
|
OpenGeniApiError
|
|
9
13
|
} from "../chunk-OO5LPTO7.js";
|
|
@@ -303,7 +307,7 @@ var OpenGeni = class {
|
|
|
303
307
|
constructor(options) {
|
|
304
308
|
if (!options.apiKey) throw new TypeError("OpenGeni requires an apiKey.");
|
|
305
309
|
if (!options.organizationId) throw new TypeError("OpenGeni requires an organizationId.");
|
|
306
|
-
this.client = new
|
|
310
|
+
this.client = new OpenGeniEmbeddingClient({
|
|
307
311
|
baseUrl: options.baseUrl ?? DEFAULT_OPENGENI_BASE_URL,
|
|
308
312
|
apiKey: options.apiKey,
|
|
309
313
|
...options.fetch ? { fetch: options.fetch } : {}
|
|
@@ -335,35 +339,29 @@ var OpenGeni = class {
|
|
|
335
339
|
}
|
|
336
340
|
/**
|
|
337
341
|
* Address one conversation; the session is created lazily on the first send.
|
|
338
|
-
*
|
|
339
|
-
*
|
|
342
|
+
* Identity selects authority, not the conversation address. Workspace
|
|
343
|
+
* membership must be provisioned by the host's explicit onboarding flow.
|
|
344
|
+
* Legacy user-namespaced conversations remain accessible by their session ID.
|
|
340
345
|
*/
|
|
341
346
|
async chat(options) {
|
|
342
347
|
if (!options.conversation) throw new TypeError("chat() requires a conversation id.");
|
|
343
348
|
const agentAccess = options.agentAccess ?? "session";
|
|
344
|
-
const memoryScope = options.memory === false ? "off" : options.memory === void 0 ? agentAccess : options.memory;
|
|
349
|
+
const memoryScope = options.memory === false ? "off" : options.memory === void 0 ? agentAccess === "session" ? "off" : agentAccess : options.memory;
|
|
345
350
|
if (memoryScope === "user" && !options.user) {
|
|
346
351
|
throw new OpenGeniChatError(
|
|
347
352
|
"memory_scope_requires_user",
|
|
348
|
-
'memory: "user" requires
|
|
353
|
+
'memory: "user" requires an authenticated product user.'
|
|
349
354
|
);
|
|
350
355
|
}
|
|
351
|
-
const
|
|
356
|
+
const client = options.user ? this.client.asUser(options.user, { source: this.source }) : this.client;
|
|
352
357
|
const workspaceId = await this.workspaceId(options);
|
|
353
|
-
const sessionId = await chatSessionId(workspaceId, options.conversation
|
|
354
|
-
const session = await this.findSession(workspaceId, sessionId);
|
|
355
|
-
if (session && endUser && !sameEndUser(session.endUser ?? null, endUser)) {
|
|
356
|
-
throw new OpenGeniChatError(
|
|
357
|
-
"conversation_not_authorized",
|
|
358
|
-
"This conversation belongs to a different user."
|
|
359
|
-
);
|
|
360
|
-
}
|
|
358
|
+
const sessionId = options.sessionId ?? await chatSessionId(workspaceId, options.conversation);
|
|
359
|
+
const session = await this.findSession(client, workspaceId, sessionId);
|
|
361
360
|
const buildCreate = (text, importedHistory) => {
|
|
362
361
|
const context = options.create?.modelContext === void 0 && importedHistory ? formatImportedHistory(importedHistory) : void 0;
|
|
363
362
|
return {
|
|
364
363
|
agentAccess,
|
|
365
364
|
memoryScope,
|
|
366
|
-
...endUser ? { endUser } : {},
|
|
367
365
|
...options.model !== void 0 ? { model: options.model } : {},
|
|
368
366
|
...options.instructions !== void 0 ? { instructions: options.instructions } : {},
|
|
369
367
|
...options.skills !== void 0 ? { skills: options.skills } : {},
|
|
@@ -375,7 +373,7 @@ var OpenGeni = class {
|
|
|
375
373
|
idempotencyKey: chatIdempotencyKey(sessionId)
|
|
376
374
|
};
|
|
377
375
|
};
|
|
378
|
-
return new Chat(
|
|
376
|
+
return new Chat(client, {
|
|
379
377
|
workspaceId,
|
|
380
378
|
sessionId,
|
|
381
379
|
conversation: options.conversation,
|
|
@@ -384,22 +382,14 @@ var OpenGeni = class {
|
|
|
384
382
|
});
|
|
385
383
|
}
|
|
386
384
|
/**
|
|
387
|
-
* Address an existing session
|
|
388
|
-
*
|
|
389
|
-
*
|
|
390
|
-
* `conversation_not_authorized`. Pass `null` only from trusted server code
|
|
391
|
-
* that vouches for the session itself; a session reached with `null` is not
|
|
392
|
-
* checked against any user.
|
|
385
|
+
* Address an existing session with native API authorization. The same shared
|
|
386
|
+
* session can be opened by different authorized users. Pass null only for an
|
|
387
|
+
* explicitly service-owned operation; the API still enforces service access.
|
|
393
388
|
*/
|
|
394
389
|
async chatBySessionId(target) {
|
|
395
|
-
const
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
"conversation_not_authorized",
|
|
399
|
-
"This conversation belongs to a different user."
|
|
400
|
-
);
|
|
401
|
-
}
|
|
402
|
-
return new Chat(this, {
|
|
390
|
+
const client = target.user !== null ? this.client.asUser(target.user, { source: this.source }) : this.client;
|
|
391
|
+
const session = await client.getSession(target.workspaceId, target.sessionId);
|
|
392
|
+
return new Chat(client, {
|
|
403
393
|
workspaceId: target.workspaceId,
|
|
404
394
|
sessionId: target.sessionId,
|
|
405
395
|
conversation: null,
|
|
@@ -407,9 +397,9 @@ var OpenGeni = class {
|
|
|
407
397
|
buildCreate: null
|
|
408
398
|
});
|
|
409
399
|
}
|
|
410
|
-
async findSession(workspaceId, sessionId) {
|
|
400
|
+
async findSession(client, workspaceId, sessionId) {
|
|
411
401
|
try {
|
|
412
|
-
return await
|
|
402
|
+
return await client.getSession(workspaceId, sessionId);
|
|
413
403
|
} catch (error) {
|
|
414
404
|
if (error instanceof OpenGeniApiError && error.status === 404) return null;
|
|
415
405
|
throw error;
|
|
@@ -417,20 +407,20 @@ var OpenGeni = class {
|
|
|
417
407
|
}
|
|
418
408
|
async listSessions(options) {
|
|
419
409
|
const workspaceId = await this.workspaceId(options);
|
|
420
|
-
|
|
410
|
+
const client = options.user ? this.client.asUser(options.user, { source: this.source }) : this.client;
|
|
411
|
+
return await client.requestJson(
|
|
421
412
|
"GET",
|
|
422
413
|
`/v1/workspaces/${workspaceId}/sessions`,
|
|
423
414
|
void 0,
|
|
424
415
|
{
|
|
425
|
-
...options.limit !== void 0 ? { limit: String(options.limit) } : {}
|
|
426
|
-
...options.user ? { endUserSource: this.source, endUserId: options.user } : {}
|
|
416
|
+
...options.limit !== void 0 ? { limit: String(options.limit) } : {}
|
|
427
417
|
}
|
|
428
418
|
);
|
|
429
419
|
}
|
|
430
420
|
};
|
|
431
421
|
var Chat = class {
|
|
432
|
-
constructor(
|
|
433
|
-
this.
|
|
422
|
+
constructor(client, init) {
|
|
423
|
+
this.client = client;
|
|
434
424
|
this.workspaceId = init.workspaceId;
|
|
435
425
|
this.sessionId = init.sessionId;
|
|
436
426
|
this.conversation = init.conversation;
|
|
@@ -482,7 +472,7 @@ var Chat = class {
|
|
|
482
472
|
let lastAssistantTurn = null;
|
|
483
473
|
let after = 0;
|
|
484
474
|
while (true) {
|
|
485
|
-
const result = await this.
|
|
475
|
+
const result = await this.client.listEventPage(this.workspaceId, this.sessionId, {
|
|
486
476
|
after,
|
|
487
477
|
includeTypes: [
|
|
488
478
|
"user.message",
|
|
@@ -537,7 +527,7 @@ var Chat = class {
|
|
|
537
527
|
if (!this.buildCreate) {
|
|
538
528
|
throw new OpenGeniChatError("session_missing", "This session no longer exists.");
|
|
539
529
|
}
|
|
540
|
-
const created = await this.
|
|
530
|
+
const created = await this.client.createSession(
|
|
541
531
|
this.workspaceId,
|
|
542
532
|
this.buildCreate(text, importedHistory)
|
|
543
533
|
);
|
|
@@ -546,31 +536,31 @@ var Chat = class {
|
|
|
546
536
|
return { after: 0, turnId: created.initialTurnId };
|
|
547
537
|
}
|
|
548
538
|
}
|
|
549
|
-
const event = await this.
|
|
539
|
+
const event = await this.client.sendMessage(this.workspaceId, this.sessionId, text);
|
|
550
540
|
return submittedFrom(event);
|
|
551
541
|
}
|
|
552
542
|
async submitSteer(text, importedHistory) {
|
|
553
543
|
if (!this.session) return await this.submit(text, importedHistory);
|
|
554
|
-
const result = await this.
|
|
544
|
+
const result = await this.client.steerMessage(this.workspaceId, this.sessionId, text);
|
|
555
545
|
return { after: result.accepted.sequence, turnId: result.turn.id ?? null };
|
|
556
546
|
}
|
|
557
547
|
async submitResponse(input) {
|
|
558
548
|
let event;
|
|
559
549
|
if ("decision" in input) {
|
|
560
|
-
event = await this.
|
|
550
|
+
event = await this.client.sendApprovalDecision(this.workspaceId, this.sessionId, {
|
|
561
551
|
approvalId: input.requestId,
|
|
562
552
|
decision: input.decision,
|
|
563
553
|
...input.message !== void 0 ? { message: input.message } : {}
|
|
564
554
|
});
|
|
565
555
|
} else if ("answers" in input) {
|
|
566
|
-
event = await this.
|
|
556
|
+
event = await this.client.submitHumanInputResponse(
|
|
567
557
|
this.workspaceId,
|
|
568
558
|
this.sessionId,
|
|
569
559
|
input.requestId,
|
|
570
560
|
{ outcome: "answered", answers: input.answers }
|
|
571
561
|
);
|
|
572
562
|
} else {
|
|
573
|
-
event = await this.
|
|
563
|
+
event = await this.client.submitHumanInputResponse(
|
|
574
564
|
this.workspaceId,
|
|
575
565
|
this.sessionId,
|
|
576
566
|
input.requestId,
|
|
@@ -587,7 +577,7 @@ var Chat = class {
|
|
|
587
577
|
else signal?.addEventListener("abort", onAbort, { once: true });
|
|
588
578
|
const fold = new ChatTurnFold(this.workspaceId, this.sessionId, submitted.turnId);
|
|
589
579
|
try {
|
|
590
|
-
for await (const event of this.
|
|
580
|
+
for await (const event of this.client.streamEvents(this.workspaceId, this.sessionId, {
|
|
591
581
|
after: submitted.after,
|
|
592
582
|
signal: upstream.signal
|
|
593
583
|
})) {
|
|
@@ -659,9 +649,6 @@ function abortError() {
|
|
|
659
649
|
error.name = "AbortError";
|
|
660
650
|
return error;
|
|
661
651
|
}
|
|
662
|
-
function sameEndUser(left, right) {
|
|
663
|
-
return left !== null && left.source === right.source && left.id === right.id;
|
|
664
|
-
}
|
|
665
652
|
|
|
666
653
|
// src/chat/http.ts
|
|
667
654
|
var CHAT_CONVERSATION_HEADER = "x-opengeni-conversation";
|