@opengeni/core 1.4.0 → 1.4.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/dist/application/modal-native-live-declaration-join.d.ts +37 -0
- package/dist/application/modal-native-original-configuration.d.ts +79 -0
- package/dist/domain/capabilities.d.ts +1 -0
- package/dist/domain/knowledge-messages.d.ts +2 -2
- package/dist/domain/realtime-voice-billing.d.ts +21 -7
- package/dist/domain/session-start-timing.d.ts +1 -1
- package/dist/domain/session-tool-policy.d.ts +7 -3
- package/dist/domain/voice-input-billing.d.ts +3 -2
- package/dist/index.js +575 -523
- package/dist/index.js.map +1 -1
- package/package.json +12 -12
- package/src/application/modal-native-live-declaration-join.ts +196 -0
- package/src/application/modal-native-original-configuration.ts +261 -0
- package/src/default-session-model.ts +58 -88
- package/src/domain/capabilities.ts +44 -2
- package/src/domain/realtime-voice-billing.ts +80 -10
- package/src/domain/session-start-timing.ts +5 -0
- package/src/domain/session-tool-policy.ts +6 -2
- package/src/domain/sessions.ts +130 -96
- package/src/domain/voice-input-billing.ts +9 -4
- package/src/model-catalog.ts +32 -38
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { Settings } from "@opengeni/config";
|
|
2
|
+
import { ModalNativePreparationDeclarationV2 } from "@opengeni/contracts/modal-native-proof-v2";
|
|
3
|
+
import { type Database, type ModalNativeLiveOriginProjection, type ModalNativeLiveOriginResult } from "@opengeni/db";
|
|
4
|
+
import { type NativeOriginalConfigurationSample } from "./modal-native-original-configuration.js";
|
|
5
|
+
type JoinSettings = Pick<Settings, "delegationSecret" | "modalTokenId" | "modalTokenSecret" | "modalEnvironment" | "environmentsEncryptionKey">;
|
|
6
|
+
/** Sensitive request-local data only. Do not publish/log/cache across commit.
|
|
7
|
+
* The sample contains immutable credential strings which disposal cannot erase.
|
|
8
|
+
* This result has no native-I/O, replay, custody or effect authority. */
|
|
9
|
+
export type NativeLiveDeclarationJoin = Readonly<{
|
|
10
|
+
requestId: string;
|
|
11
|
+
declaration: ModalNativePreparationDeclarationV2;
|
|
12
|
+
projection: ModalNativeLiveOriginProjection;
|
|
13
|
+
configuration: NativeOriginalConfigurationSample;
|
|
14
|
+
}>;
|
|
15
|
+
export type NativeLiveDeclarationJoinResult = {
|
|
16
|
+
kind: "joined_data";
|
|
17
|
+
data: NativeLiveDeclarationJoin;
|
|
18
|
+
} | {
|
|
19
|
+
kind: "off";
|
|
20
|
+
} | {
|
|
21
|
+
kind: "refused";
|
|
22
|
+
} | Exclude<ModalNativeLiveOriginResult, {
|
|
23
|
+
kind: "live";
|
|
24
|
+
}>;
|
|
25
|
+
/** Own bytes BEFORE either verifying or parsing. After the blocking SQL join,
|
|
26
|
+
* re-read the explicit CURRENT deployment root/profile and reverify current
|
|
27
|
+
* expiry over those SAME owned bytes. A historical MAC witness is insufficient.
|
|
28
|
+
* No tenant/subject GUC change, general access-token resolver, provider await,
|
|
29
|
+
* fallback, registration or error-to-success conversion occurs here.
|
|
30
|
+
*
|
|
31
|
+
* Input execution/human fields are signed CORRELATION, not caller authority:
|
|
32
|
+
* compare them to the exact DB-derived accepted original projection. This does
|
|
33
|
+
* NOT independently prove that the canonical worker produced the request.
|
|
34
|
+
* Enter an existing scoped transaction before any tenancy/control/row lock;
|
|
35
|
+
* consume the result in that transaction and dispose its sample afterward. */
|
|
36
|
+
export declare function lockNativeLiveDeclarationJoinTx(scopedTx: Database, settings: JoinSettings, envelope: string, inputBody: Uint8Array): Promise<NativeLiveDeclarationJoinResult>;
|
|
37
|
+
export {};
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import type { Settings } from "@opengeni/config";
|
|
2
|
+
import { ModalNativePreparationDeclarationV2 } from "@opengeni/contracts/modal-native-proof-v2";
|
|
3
|
+
declare const SUBKEY_DOMAIN = "opengeni:modal-native:configuration-equality:subkey:v2";
|
|
4
|
+
declare const MESSAGE_DOMAIN = "opengeni:modal-native:configuration-equality:framed:v2\0";
|
|
5
|
+
type ConfigurationSettings = Pick<Settings, "modalTokenId" | "modalTokenSecret" | "modalEnvironment" | "environmentsEncryptionKey">;
|
|
6
|
+
export type NativeOriginalConfigurationSnapshot = Readonly<{
|
|
7
|
+
serverUrl: string;
|
|
8
|
+
tokenId: string;
|
|
9
|
+
tokenSecret: string;
|
|
10
|
+
environment: string;
|
|
11
|
+
}>;
|
|
12
|
+
declare function readProfile(environment: string): Readonly<{
|
|
13
|
+
protocol: "modal-direct-original-read-grpc-v1";
|
|
14
|
+
version: 1;
|
|
15
|
+
sourceGitBlob: "7599f5b80cf111a25f78f427cfb2616d7e24b36c";
|
|
16
|
+
serverUrl: "https://api.modal.com:443";
|
|
17
|
+
serverSelection: "host-pinned-modal-0.9-default";
|
|
18
|
+
credentialSelection: "explicit-deployment-settings-pair-only";
|
|
19
|
+
environmentSelection: "explicit-own-settings-no-default";
|
|
20
|
+
environment: string;
|
|
21
|
+
environmentTransmittedByCpReads: false;
|
|
22
|
+
namespaceSelection: "unbound-until-authenticated-once-capture";
|
|
23
|
+
modalProjectionVersion: "0.9.0";
|
|
24
|
+
grpcJsVersion: "1.14.4";
|
|
25
|
+
protobufJsVersion: "7.6.5";
|
|
26
|
+
rpcPrefix: "/modal.client.ModalClient/";
|
|
27
|
+
methods: readonly ["AuthTokenGet", "WorkspaceNameLookup", "TaskGetCommandRouterAccess"];
|
|
28
|
+
authHeaders: {
|
|
29
|
+
readonly clientType: "8";
|
|
30
|
+
readonly clientVersion: "1.0.0";
|
|
31
|
+
readonly libmodalVersion: "modal-js/0.9.0";
|
|
32
|
+
};
|
|
33
|
+
tlsPolicy: "explicit-node-tls-rootCertificates-v1";
|
|
34
|
+
tlsRootsSha256: string;
|
|
35
|
+
retries: 0;
|
|
36
|
+
nativeChainDeadlineMs: 30000;
|
|
37
|
+
maxWireBytes: 1048576;
|
|
38
|
+
}>;
|
|
39
|
+
type PrivateDescription = Readonly<{
|
|
40
|
+
protocol: "opengeni-modal-native-configuration-equality";
|
|
41
|
+
version: 2;
|
|
42
|
+
purpose: "original-native-custody-proof";
|
|
43
|
+
configurationCaptureRef: ModalNativePreparationDeclarationV2["configurationCaptureRef"];
|
|
44
|
+
proofGrantRef: ModalNativePreparationDeclarationV2["proofGrantRef"];
|
|
45
|
+
declarationJson: string;
|
|
46
|
+
declarationSha256: string;
|
|
47
|
+
profile: ReturnType<typeof readProfile>;
|
|
48
|
+
keySelection: "existing-environments-encryption-root-current-only";
|
|
49
|
+
algorithm: "hmac-sha256";
|
|
50
|
+
subkeyDomain: typeof SUBKEY_DOMAIN;
|
|
51
|
+
messageDomain: typeof MESSAGE_DOMAIN;
|
|
52
|
+
}>;
|
|
53
|
+
/** Sensitive PRIVATE storage draft, not proof that any row or grant committed. */
|
|
54
|
+
export type NativeOriginalConfigurationDraftV2 = Readonly<{
|
|
55
|
+
description: PrivateDescription;
|
|
56
|
+
equality: Uint8Array;
|
|
57
|
+
}>;
|
|
58
|
+
declare const sampleBrand: unique symbol;
|
|
59
|
+
export type NativeOriginalConfigurationSample = Readonly<{
|
|
60
|
+
[sampleBrand]: true;
|
|
61
|
+
}>;
|
|
62
|
+
/** Samples ONLY explicit own settings, without environment/profile/SDK lookup.
|
|
63
|
+
* A parsed declaration merely supplies correlation. Genuine known app/image
|
|
64
|
+
* provenance and same-transaction host/grant/admission checks remain external.
|
|
65
|
+
*/
|
|
66
|
+
export declare function sampleNativeOriginalConfiguration(settings: ConfigurationSettings, declarationBytes: Uint8Array): NativeOriginalConfigurationSample | null;
|
|
67
|
+
/** Private draft extraction for protected storage only; never a status DTO. */
|
|
68
|
+
export declare function privateNativeOriginalConfigurationDraft(sample: NativeOriginalConfigurationSample): NativeOriginalConfigurationDraftV2 | null;
|
|
69
|
+
/** Same sampled strings for a future authenticated native caller; NOT a grant. */
|
|
70
|
+
export declare function nativeOriginalConfigurationSnapshot(sample: NativeOriginalConfigurationSample): NativeOriginalConfigurationSnapshot | null;
|
|
71
|
+
/** PRIVATE equality check only. No public oracle, grant renewal or key fallback.
|
|
72
|
+
* Restart reconstruction still requires an authenticated protected original row.
|
|
73
|
+
*/
|
|
74
|
+
export declare function currentNativeOriginalConfigurationMatches(sample: NativeOriginalConfigurationSample, settings: ConfigurationSettings): boolean;
|
|
75
|
+
/** Wipes owned mutable copies, not JS immutable strings or native I/O/custody.
|
|
76
|
+
* A future owning native caller must join its real callbacks separately.
|
|
77
|
+
*/
|
|
78
|
+
export declare function disposeNativeOriginalConfigurationSample(sample: NativeOriginalConfigurationSample): void;
|
|
79
|
+
export {};
|
|
@@ -8,6 +8,7 @@ export declare function buildCapabilityCatalog(input: {
|
|
|
8
8
|
settings: Settings;
|
|
9
9
|
subjectId?: string | null;
|
|
10
10
|
}): Promise<CapabilityCatalogResponse>;
|
|
11
|
+
export declare function applyOperatorOAuthClientRequirement(item: CapabilityCatalogItem, configured: (issuer: string) => boolean): CapabilityCatalogItem;
|
|
11
12
|
export declare function createCatalogItem(input: {
|
|
12
13
|
db: Database;
|
|
13
14
|
accountId: string;
|
|
@@ -17,7 +17,7 @@ export declare function retainKnowledgeMessage(db: Database, context: KnowledgeC
|
|
|
17
17
|
messageId?: never;
|
|
18
18
|
reused?: never;
|
|
19
19
|
} | {
|
|
20
|
-
|
|
20
|
+
reason?: never;
|
|
21
21
|
retained: boolean;
|
|
22
22
|
entryId: string;
|
|
23
23
|
revisionId: string;
|
|
@@ -32,7 +32,7 @@ export declare function retainKnowledgeMessage(db: Database, context: KnowledgeC
|
|
|
32
32
|
outcome: "archived" | "pending" | "published" | "rejected";
|
|
33
33
|
reviewBatchId: string | null;
|
|
34
34
|
replayed: boolean;
|
|
35
|
-
|
|
35
|
+
reason?: never;
|
|
36
36
|
reused?: never;
|
|
37
37
|
retained: boolean;
|
|
38
38
|
messageId: string;
|
|
@@ -11,12 +11,6 @@ export type DeploymentRealtimeVoice = {
|
|
|
11
11
|
configured: boolean;
|
|
12
12
|
pricing: RealtimeVoicePricing | null;
|
|
13
13
|
};
|
|
14
|
-
/**
|
|
15
|
-
* Live-voice models the deployment pays the provider for. Connected Codex,
|
|
16
|
-
* SuperGrok, and a workspace's own Gateway key are paid by the workspace and
|
|
17
|
-
* return null. (The catalog lists hosted GPT Live instead of the managed
|
|
18
|
-
* Gateway choices when both are configured; both remain priced and gated.)
|
|
19
|
-
*/
|
|
20
14
|
export declare function deploymentRealtimeVoice(settings: Settings, model: SessionRealtimeModel | string): DeploymentRealtimeVoice | null;
|
|
21
15
|
export type RealtimeVoiceUnavailableCode = "not_configured" | "pricing_unconfigured";
|
|
22
16
|
/** The deployment cannot offer this live-voice model at all (not a credit refusal). */
|
|
@@ -28,6 +22,24 @@ export declare class RealtimeVoiceUnavailableError extends Error {
|
|
|
28
22
|
/** Static offer check: configured, and priced whenever credits are enforced. */
|
|
29
23
|
export declare function realtimeVoiceOfferProblem(settings: Settings, voice: DeploymentRealtimeVoice): RealtimeVoiceUnavailableError | null;
|
|
30
24
|
export declare const REALTIME_VOICE_INSUFFICIENT_CREDITS_MESSAGE = "Live voice needs Opengeni credits. Add credits to continue.";
|
|
25
|
+
/**
|
|
26
|
+
* Credits voice can spend (general and signup credits), only model-scoped
|
|
27
|
+
* promotional credits, or neither.
|
|
28
|
+
*/
|
|
29
|
+
export type VoiceCreditStanding = "spendable" | "promotional_only" | "none";
|
|
30
|
+
/** `balance` must be the voice-spendable balance (see {@link VOICE_CREDIT_USAGE}). */
|
|
31
|
+
export declare function voiceCreditStanding(balance: {
|
|
32
|
+
balanceMicros: number;
|
|
33
|
+
promotionalCredits?: readonly {
|
|
34
|
+
remainingMicros: number;
|
|
35
|
+
}[] | undefined;
|
|
36
|
+
}): VoiceCreditStanding;
|
|
37
|
+
/**
|
|
38
|
+
* Insufficient-credit copy for voice. Signup credits pay for voice like
|
|
39
|
+
* general credits; other promotional credits are scoped to chat models, so an
|
|
40
|
+
* account holding only those must not be told it has nothing.
|
|
41
|
+
*/
|
|
42
|
+
export declare function voiceInsufficientCreditsMessage(feature: "Live voice" | "Voice input", standing: VoiceCreditStanding): string;
|
|
31
43
|
export type RealtimeVoiceSettlement = {
|
|
32
44
|
/** Credits debited by this settlement call (0 on replay). */
|
|
33
45
|
debitedMicros: number;
|
|
@@ -38,7 +50,7 @@ export type RealtimeVoiceSettlement = {
|
|
|
38
50
|
* Credit admission and time metering for deployment-funded live voice.
|
|
39
51
|
*
|
|
40
52
|
* Admission mirrors voice-input admission (same refusal codes and HTTP
|
|
41
|
-
* shape): spendable general
|
|
53
|
+
* shape): voice-spendable credits (general plus signup) must be positive, the workspace/member
|
|
42
54
|
* allowance must not be exhausted, and the static monthly cost cap applies.
|
|
43
55
|
* Metering bills every started minute of each issued provider connection,
|
|
44
56
|
* measured only from server-observed facts (connection claim time, owner
|
|
@@ -63,6 +75,8 @@ export declare function createRealtimeVoiceBilling(deps: {
|
|
|
63
75
|
}): Promise<void>;
|
|
64
76
|
/** Spendable credits are positive (always true when credits are not enforced). */
|
|
65
77
|
hasSpendableCredits(accountId: string): Promise<boolean>;
|
|
78
|
+
/** Credit standing for live voice ("spendable" when credits are not enforced). */
|
|
79
|
+
creditStanding(accountId: string): Promise<VoiceCreditStanding>;
|
|
66
80
|
/**
|
|
67
81
|
* Settle every started minute observed so far for one live-voice mode and
|
|
68
82
|
* report whether the call must stop. Safe to call repeatedly and
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type Observability } from "@opengeni/observability";
|
|
2
|
-
type SessionStartPhase = "workspace_read" | "model_catalog_initial" | "default_model" | "model_catalog_effective" | "capability_settings" | "initiator_freeze" | "allowance" | "shell_insert" | "initialize" | "event_fanout" | "workflow_wake" | "session_reload";
|
|
2
|
+
type SessionStartPhase = "workspace_read" | "idempotent_replay" | "model_catalog_initial" | "default_model" | "model_catalog_effective" | "capability_settings" | "resource_validation" | "rig_binding" | "model_admission" | "connection_freeze" | "initiator_freeze" | "allowance" | "shell_insert" | "initialize" | "event_fanout" | "workflow_wake" | "session_reload";
|
|
3
3
|
export type SessionStartObservability = Pick<Observability, "startSpan">;
|
|
4
4
|
/** Content-free child spans around existing work; export is never joined and
|
|
5
5
|
* diagnostic failures cannot alter the lifecycle or its exact error. */
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type Settings } from "@opengeni/config";
|
|
2
2
|
import { type AgentToolEnvironment, type AgentMediaAttachment, type Session, type SessionTurn, type SessionEffectiveToolPolicy, type SessionToolPolicy, type ToolRef } from "@opengeni/contracts";
|
|
3
|
-
import { type Database } from "@opengeni/db";
|
|
3
|
+
import { requireWorkspace, type Database } from "@opengeni/db";
|
|
4
4
|
export type ResolvedSessionToolPolicy = {
|
|
5
5
|
toolRefs: ToolRef[];
|
|
6
6
|
effectivePolicy: SessionEffectiveToolPolicy;
|
|
@@ -35,7 +35,9 @@ export declare function resolveTurnToolPolicy(input: Omit<SessionToolPolicyInput
|
|
|
35
35
|
turn: Pick<SessionTurn, "tools" | "metadata">;
|
|
36
36
|
}): ResolvedSessionToolPolicy;
|
|
37
37
|
/** Resolve availability and defaults from the same subject-scoped registry read. */
|
|
38
|
-
export declare function workspaceSessionToolPolicyContext(db: Database, workspaceId: string, settings: Settings, subjectId?: string
|
|
38
|
+
export declare function workspaceSessionToolPolicyContext(db: Database, workspaceId: string, settings: Settings, subjectId?: string,
|
|
39
|
+
/** An in-flight read of this exact workspace a caller already started. */
|
|
40
|
+
workspaceRead?: ReturnType<typeof requireWorkspace>): Promise<{
|
|
39
41
|
workspaceServerIds: string[];
|
|
40
42
|
workspaceDefaultServerIds: string[];
|
|
41
43
|
}>;
|
|
@@ -73,7 +75,9 @@ export declare function workspaceSessionEffectiveToolsContext(deps: {
|
|
|
73
75
|
db: Database;
|
|
74
76
|
settings: Settings;
|
|
75
77
|
objectStorage?: unknown;
|
|
76
|
-
}, workspaceId: string, subjectId: string, sessions: readonly Session[]
|
|
78
|
+
}, workspaceId: string, subjectId: string, sessions: readonly Session[],
|
|
79
|
+
/** An in-flight read of this exact workspace a caller already started. */
|
|
80
|
+
workspaceRead?: ReturnType<typeof requireWorkspace>): Promise<SessionEffectiveToolsContext>;
|
|
77
81
|
/** The server can prove attachment policy, not successful future provider calls. */
|
|
78
82
|
export declare function sessionEffectiveToolProjectionInput(session: Session & {
|
|
79
83
|
agent: NonNullable<Session["agent"]>;
|
|
@@ -23,8 +23,9 @@ export declare function voiceInputBillableUsage(input: {
|
|
|
23
23
|
basis: VoiceInputBillingBasis;
|
|
24
24
|
};
|
|
25
25
|
/**
|
|
26
|
-
* Same admission shape as knowledge-search and session admission:
|
|
27
|
-
*
|
|
26
|
+
* Same admission shape as knowledge-search and session admission:
|
|
27
|
+
* voice-spendable credits (general plus signup, not model-scoped promotional
|
|
28
|
+
* credits) must be positive, the workspace/member
|
|
28
29
|
* allowance must not be exhausted, and a static monthly cost cap applies.
|
|
29
30
|
* Admission is a read, not a reservation; settlement is post-use and may take
|
|
30
31
|
* an account below zero by at most the concurrent in-flight calls.
|