@valon-technologies/gestalt 0.0.1-alpha.36 → 0.0.1-alpha.38
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/package.json +1 -1
- package/src/agent-access.ts +15 -20
- package/src/agent-conversions.ts +31 -2
- package/src/agent.ts +77 -50
- package/src/api.ts +36 -4
- package/src/app-access.ts +7 -49
- package/src/index.ts +0 -1
- package/src/internal/gen/v1/agent_pb.ts +34 -94
- package/src/internal/gen/v1/app_pb.ts +179 -125
- package/src/internal/gen/v1/runtime_pb.ts +6 -1
- package/src/internal/gen/v1/test_pb.ts +66 -0
- package/src/internal/gen/v1/workflow_pb.ts +49 -49
- package/src/runtime.ts +39 -22
- package/src/workflow-access.ts +23 -45
- package/src/workflow.ts +74 -15
- package/src/invocation-context.ts +0 -15
package/src/workflow.ts
CHANGED
|
@@ -18,9 +18,16 @@ import {
|
|
|
18
18
|
type Request,
|
|
19
19
|
type Subject,
|
|
20
20
|
type SubjectInput,
|
|
21
|
+
type SubjectPermission,
|
|
21
22
|
errorMessage,
|
|
22
23
|
} from "./api.ts";
|
|
23
|
-
import {
|
|
24
|
+
import {
|
|
25
|
+
SubjectContextSchema,
|
|
26
|
+
SubjectPermissionContextSchema,
|
|
27
|
+
type RequestContext as ProtoRequestContext,
|
|
28
|
+
type SubjectContext,
|
|
29
|
+
type SubjectPermissionContext,
|
|
30
|
+
} from "./internal/gen/v1/app_pb.ts";
|
|
24
31
|
import {
|
|
25
32
|
ApplyWorkflowProviderDefinitionRequestSchema,
|
|
26
33
|
BoundWorkflowTargetSchema,
|
|
@@ -65,6 +72,7 @@ import {
|
|
|
65
72
|
type ApplyWorkflowProviderDefinitionRequest as ProtoApplyWorkflowProviderDefinitionRequest,
|
|
66
73
|
type BoundWorkflowTarget as ProtoBoundWorkflowTarget,
|
|
67
74
|
type CancelWorkflowProviderRunRequest as ProtoCancelWorkflowProviderRunRequest,
|
|
75
|
+
type DeleteWorkflowProviderDefinitionRequest as ProtoDeleteWorkflowProviderDefinitionRequest,
|
|
68
76
|
type DeliverWorkflowProviderEventRequest as ProtoDeliverWorkflowProviderEventRequest,
|
|
69
77
|
type GetWorkflowProviderDefinitionRequest as ProtoGetWorkflowProviderDefinitionRequest,
|
|
70
78
|
type GetWorkflowProviderRunEventsRequest as ProtoGetWorkflowProviderRunEventsRequest,
|
|
@@ -402,18 +410,23 @@ export interface ApplyWorkflowProviderDefinitionRequest {
|
|
|
402
410
|
spec?: WorkflowDefinitionSpec | undefined;
|
|
403
411
|
idempotencyKey?: string | undefined;
|
|
404
412
|
requestedBySubjectId?: string | undefined;
|
|
413
|
+
context?: ProtoRequestContext | undefined;
|
|
405
414
|
}
|
|
406
415
|
|
|
407
416
|
export interface GetWorkflowProviderDefinitionRequest {
|
|
408
417
|
definitionId: string;
|
|
418
|
+
context?: ProtoRequestContext | undefined;
|
|
409
419
|
}
|
|
410
420
|
|
|
411
|
-
export interface ListWorkflowProviderDefinitionsRequest {
|
|
421
|
+
export interface ListWorkflowProviderDefinitionsRequest {
|
|
422
|
+
context?: ProtoRequestContext | undefined;
|
|
423
|
+
}
|
|
412
424
|
|
|
413
425
|
export interface SetWorkflowProviderDefinitionPausedRequest {
|
|
414
426
|
definitionId: string;
|
|
415
427
|
paused: boolean;
|
|
416
428
|
requestedBySubjectId?: string | undefined;
|
|
429
|
+
context?: ProtoRequestContext | undefined;
|
|
417
430
|
}
|
|
418
431
|
|
|
419
432
|
export interface SetWorkflowProviderActivationPausedRequest {
|
|
@@ -421,10 +434,12 @@ export interface SetWorkflowProviderActivationPausedRequest {
|
|
|
421
434
|
activationId: string;
|
|
422
435
|
paused: boolean;
|
|
423
436
|
requestedBySubjectId?: string | undefined;
|
|
437
|
+
context?: ProtoRequestContext | undefined;
|
|
424
438
|
}
|
|
425
439
|
|
|
426
440
|
export interface DeleteWorkflowProviderDefinitionRequest {
|
|
427
441
|
definitionId: string;
|
|
442
|
+
context?: ProtoRequestContext | undefined;
|
|
428
443
|
}
|
|
429
444
|
|
|
430
445
|
export interface StartWorkflowProviderRunRequest {
|
|
@@ -435,10 +450,12 @@ export interface StartWorkflowProviderRunRequest {
|
|
|
435
450
|
createdBySubjectId?: string | undefined;
|
|
436
451
|
runAs?: SubjectInput | undefined;
|
|
437
452
|
workflowKey?: string | undefined;
|
|
453
|
+
context?: ProtoRequestContext | undefined;
|
|
438
454
|
}
|
|
439
455
|
|
|
440
456
|
export interface GetWorkflowProviderRunRequest {
|
|
441
457
|
runId: string;
|
|
458
|
+
context?: ProtoRequestContext | undefined;
|
|
442
459
|
}
|
|
443
460
|
|
|
444
461
|
export interface ListWorkflowProviderRunsRequest {
|
|
@@ -446,24 +463,29 @@ export interface ListWorkflowProviderRunsRequest {
|
|
|
446
463
|
pageToken?: string | undefined;
|
|
447
464
|
status?: WorkflowRunStatus | undefined;
|
|
448
465
|
targetApp?: string | undefined;
|
|
466
|
+
context?: ProtoRequestContext | undefined;
|
|
449
467
|
}
|
|
450
468
|
|
|
451
469
|
export interface GetWorkflowProviderRunEventsRequest {
|
|
452
470
|
runId: string;
|
|
471
|
+
context?: ProtoRequestContext | undefined;
|
|
453
472
|
}
|
|
454
473
|
|
|
455
474
|
export interface GetWorkflowProviderRunOutputRequest {
|
|
456
475
|
runId: string;
|
|
476
|
+
context?: ProtoRequestContext | undefined;
|
|
457
477
|
}
|
|
458
478
|
|
|
459
479
|
export interface CancelWorkflowProviderRunRequest {
|
|
460
480
|
runId: string;
|
|
461
481
|
reason: string;
|
|
482
|
+
context?: ProtoRequestContext | undefined;
|
|
462
483
|
}
|
|
463
484
|
|
|
464
485
|
export interface SignalWorkflowProviderRunRequest {
|
|
465
486
|
runId: string;
|
|
466
487
|
signal?: WorkflowSignal | undefined;
|
|
488
|
+
context?: ProtoRequestContext | undefined;
|
|
467
489
|
}
|
|
468
490
|
|
|
469
491
|
export interface SignalOrStartWorkflowProviderRunRequest {
|
|
@@ -475,6 +497,7 @@ export interface SignalOrStartWorkflowProviderRunRequest {
|
|
|
475
497
|
createdBySubjectId?: string | undefined;
|
|
476
498
|
runAs?: SubjectInput | undefined;
|
|
477
499
|
signal?: WorkflowSignal | undefined;
|
|
500
|
+
context?: ProtoRequestContext | undefined;
|
|
478
501
|
}
|
|
479
502
|
|
|
480
503
|
export interface SignalWorkflowRunResponse {
|
|
@@ -488,6 +511,7 @@ export interface DeliverWorkflowProviderEventRequest {
|
|
|
488
511
|
appName?: string | undefined;
|
|
489
512
|
event?: WorkflowEvent | undefined;
|
|
490
513
|
deliveredBySubjectId?: string | undefined;
|
|
514
|
+
context?: ProtoRequestContext | undefined;
|
|
491
515
|
}
|
|
492
516
|
|
|
493
517
|
export function workflowText(input: WorkflowText | string = {}): WorkflowText {
|
|
@@ -910,8 +934,7 @@ export function createWorkflowProviderService(provider: WorkflowProvider): Workf
|
|
|
910
934
|
));
|
|
911
935
|
},
|
|
912
936
|
async listDefinitions(request) {
|
|
913
|
-
const result = listDefinitionsResult(await invokeWorkflowProvider("list definitions", () => provider.listDefinitions(
|
|
914
|
-
void request;
|
|
937
|
+
const result = listDefinitionsResult(await invokeWorkflowProvider("list definitions", () => provider.listDefinitions(listWorkflowProviderDefinitionsRequestFromProto(request))));
|
|
915
938
|
return create(ListWorkflowProviderDefinitionsResponseSchema, {
|
|
916
939
|
definitions: result.definitions.map(workflowDefinitionToProto),
|
|
917
940
|
});
|
|
@@ -1570,23 +1593,28 @@ function applyWorkflowProviderDefinitionRequestFromProto(input: ProtoApplyWorkfl
|
|
|
1570
1593
|
spec: workflowDefinitionSpecFromProto(input.spec),
|
|
1571
1594
|
idempotencyKey: input.idempotencyKey,
|
|
1572
1595
|
requestedBySubjectId: input.requestedBySubjectId,
|
|
1596
|
+
context: input.context,
|
|
1573
1597
|
};
|
|
1574
1598
|
}
|
|
1575
1599
|
|
|
1576
1600
|
function getWorkflowProviderDefinitionRequestFromProto(input: ProtoGetWorkflowProviderDefinitionRequest): GetWorkflowProviderDefinitionRequest {
|
|
1577
|
-
return { definitionId: input.definitionId };
|
|
1601
|
+
return { definitionId: input.definitionId, context: input.context };
|
|
1602
|
+
}
|
|
1603
|
+
|
|
1604
|
+
function listWorkflowProviderDefinitionsRequestFromProto(input: ProtoListWorkflowProviderDefinitionsRequest): ListWorkflowProviderDefinitionsRequest {
|
|
1605
|
+
return { context: input.context };
|
|
1578
1606
|
}
|
|
1579
1607
|
|
|
1580
1608
|
function setWorkflowProviderDefinitionPausedRequestFromProto(input: ProtoSetWorkflowProviderDefinitionPausedRequest): SetWorkflowProviderDefinitionPausedRequest {
|
|
1581
|
-
return { definitionId: input.definitionId, paused: input.paused, requestedBySubjectId: input.requestedBySubjectId };
|
|
1609
|
+
return { definitionId: input.definitionId, paused: input.paused, requestedBySubjectId: input.requestedBySubjectId, context: input.context };
|
|
1582
1610
|
}
|
|
1583
1611
|
|
|
1584
1612
|
function setWorkflowProviderActivationPausedRequestFromProto(input: ProtoSetWorkflowProviderActivationPausedRequest): SetWorkflowProviderActivationPausedRequest {
|
|
1585
|
-
return { definitionId: input.definitionId, activationId: input.activationId, paused: input.paused, requestedBySubjectId: input.requestedBySubjectId };
|
|
1613
|
+
return { definitionId: input.definitionId, activationId: input.activationId, paused: input.paused, requestedBySubjectId: input.requestedBySubjectId, context: input.context };
|
|
1586
1614
|
}
|
|
1587
1615
|
|
|
1588
|
-
function deleteWorkflowProviderDefinitionRequestFromProto(input:
|
|
1589
|
-
return { definitionId: input.definitionId };
|
|
1616
|
+
function deleteWorkflowProviderDefinitionRequestFromProto(input: ProtoDeleteWorkflowProviderDefinitionRequest): DeleteWorkflowProviderDefinitionRequest {
|
|
1617
|
+
return { definitionId: input.definitionId, context: input.context };
|
|
1590
1618
|
}
|
|
1591
1619
|
|
|
1592
1620
|
function startWorkflowProviderRunRequestFromProto(input: ProtoStartWorkflowProviderRunRequest): StartWorkflowProviderRunRequest {
|
|
@@ -1598,11 +1626,12 @@ function startWorkflowProviderRunRequestFromProto(input: ProtoStartWorkflowProvi
|
|
|
1598
1626
|
createdBySubjectId: input.createdBySubjectId,
|
|
1599
1627
|
runAs: subjectInputFromProto(input.runAs),
|
|
1600
1628
|
workflowKey: input.workflowKey,
|
|
1629
|
+
context: input.context,
|
|
1601
1630
|
};
|
|
1602
1631
|
}
|
|
1603
1632
|
|
|
1604
1633
|
function getWorkflowProviderRunRequestFromProto(input: ProtoGetWorkflowProviderRunRequest): GetWorkflowProviderRunRequest {
|
|
1605
|
-
return { runId: input.runId };
|
|
1634
|
+
return { runId: input.runId, context: input.context };
|
|
1606
1635
|
}
|
|
1607
1636
|
|
|
1608
1637
|
function listWorkflowProviderRunsRequestFromProto(input: ProtoListWorkflowProviderRunsRequest): ListWorkflowProviderRunsRequest {
|
|
@@ -1611,23 +1640,24 @@ function listWorkflowProviderRunsRequestFromProto(input: ProtoListWorkflowProvid
|
|
|
1611
1640
|
pageToken: input.pageToken,
|
|
1612
1641
|
status: input.status as WorkflowRunStatus,
|
|
1613
1642
|
targetApp: input.targetApp,
|
|
1643
|
+
context: input.context,
|
|
1614
1644
|
};
|
|
1615
1645
|
}
|
|
1616
1646
|
|
|
1617
1647
|
function getWorkflowProviderRunEventsRequestFromProto(input: ProtoGetWorkflowProviderRunEventsRequest): GetWorkflowProviderRunEventsRequest {
|
|
1618
|
-
return { runId: input.runId };
|
|
1648
|
+
return { runId: input.runId, context: input.context };
|
|
1619
1649
|
}
|
|
1620
1650
|
|
|
1621
1651
|
function getWorkflowProviderRunOutputRequestFromProto(input: ProtoGetWorkflowProviderRunOutputRequest): GetWorkflowProviderRunOutputRequest {
|
|
1622
|
-
return { runId: input.runId };
|
|
1652
|
+
return { runId: input.runId, context: input.context };
|
|
1623
1653
|
}
|
|
1624
1654
|
|
|
1625
1655
|
function cancelWorkflowProviderRunRequestFromProto(input: ProtoCancelWorkflowProviderRunRequest): CancelWorkflowProviderRunRequest {
|
|
1626
|
-
return { runId: input.runId, reason: input.reason };
|
|
1656
|
+
return { runId: input.runId, reason: input.reason, context: input.context };
|
|
1627
1657
|
}
|
|
1628
1658
|
|
|
1629
1659
|
function signalWorkflowProviderRunRequestFromProto(input: ProtoSignalWorkflowProviderRunRequest): SignalWorkflowProviderRunRequest {
|
|
1630
|
-
return { runId: input.runId, signal: workflowSignalFromProto(input.signal) };
|
|
1660
|
+
return { runId: input.runId, signal: workflowSignalFromProto(input.signal), context: input.context };
|
|
1631
1661
|
}
|
|
1632
1662
|
|
|
1633
1663
|
function signalOrStartWorkflowProviderRunRequestFromProto(input: ProtoSignalOrStartWorkflowProviderRunRequest): SignalOrStartWorkflowProviderRunRequest {
|
|
@@ -1640,6 +1670,7 @@ function signalOrStartWorkflowProviderRunRequestFromProto(input: ProtoSignalOrSt
|
|
|
1640
1670
|
createdBySubjectId: input.createdBySubjectId,
|
|
1641
1671
|
runAs: subjectInputFromProto(input.runAs),
|
|
1642
1672
|
signal: workflowSignalFromProto(input.signal),
|
|
1673
|
+
context: input.context,
|
|
1643
1674
|
};
|
|
1644
1675
|
}
|
|
1645
1676
|
|
|
@@ -1648,6 +1679,7 @@ function deliverWorkflowProviderEventRequestFromProto(input: ProtoDeliverWorkflo
|
|
|
1648
1679
|
appName: input.appName,
|
|
1649
1680
|
event: workflowEventFromProto(input.event),
|
|
1650
1681
|
deliveredBySubjectId: input.deliveredBySubjectId,
|
|
1682
|
+
context: input.context,
|
|
1651
1683
|
};
|
|
1652
1684
|
}
|
|
1653
1685
|
|
|
@@ -1670,7 +1702,6 @@ export interface WorkflowExecutionRequest {
|
|
|
1670
1702
|
input?: Record<string, JsonInput> | undefined;
|
|
1671
1703
|
metadata?: Record<string, JsonInput> | undefined;
|
|
1672
1704
|
createdBySubjectId?: string | undefined;
|
|
1673
|
-
invocationToken?: string | undefined;
|
|
1674
1705
|
signals?: readonly WorkflowSignal[] | undefined;
|
|
1675
1706
|
steps?: Record<string, { inputs?: Record<string, unknown>; outputs?: unknown }> | undefined;
|
|
1676
1707
|
}
|
|
@@ -1844,6 +1875,9 @@ export function subjectToProto(input?: SubjectInput | Subject): SubjectContext |
|
|
|
1844
1875
|
id: input.id ?? "",
|
|
1845
1876
|
credentialSubjectId: input.credentialSubjectId ?? "",
|
|
1846
1877
|
email: input.email ?? "",
|
|
1878
|
+
displayName: input.displayName ?? "",
|
|
1879
|
+
scopes: [...(input.scopes ?? [])],
|
|
1880
|
+
permissions: subjectPermissionsToProto(input.permissions),
|
|
1847
1881
|
});
|
|
1848
1882
|
}
|
|
1849
1883
|
|
|
@@ -1853,6 +1887,9 @@ export function subjectFromProto(input?: SubjectContext): Subject | undefined {
|
|
|
1853
1887
|
id: input.id,
|
|
1854
1888
|
credentialSubjectId: input.credentialSubjectId,
|
|
1855
1889
|
email: input.email,
|
|
1890
|
+
displayName: input.displayName,
|
|
1891
|
+
scopes: [...input.scopes],
|
|
1892
|
+
permissions: subjectPermissionsFromProto(input.permissions),
|
|
1856
1893
|
};
|
|
1857
1894
|
}
|
|
1858
1895
|
|
|
@@ -1862,9 +1899,31 @@ export function subjectInputFromProto(input?: SubjectContext): SubjectInput | un
|
|
|
1862
1899
|
id: input.id,
|
|
1863
1900
|
credentialSubjectId: input.credentialSubjectId,
|
|
1864
1901
|
email: input.email,
|
|
1902
|
+
displayName: input.displayName,
|
|
1903
|
+
scopes: [...input.scopes],
|
|
1904
|
+
permissions: subjectPermissionsFromProto(input.permissions),
|
|
1865
1905
|
};
|
|
1866
1906
|
}
|
|
1867
1907
|
|
|
1908
|
+
function subjectPermissionsFromProto(
|
|
1909
|
+
permissions: readonly SubjectPermissionContext[],
|
|
1910
|
+
): SubjectPermission[] {
|
|
1911
|
+
return permissions.map((permission) => ({
|
|
1912
|
+
app: permission.app,
|
|
1913
|
+
operations: permission.allOperations ? [] : [...permission.operations],
|
|
1914
|
+
}));
|
|
1915
|
+
}
|
|
1916
|
+
|
|
1917
|
+
function subjectPermissionsToProto(
|
|
1918
|
+
permissions?: readonly SubjectPermission[] | undefined,
|
|
1919
|
+
): SubjectPermissionContext[] {
|
|
1920
|
+
return permissions?.map((permission) => create(SubjectPermissionContextSchema, {
|
|
1921
|
+
app: permission.app,
|
|
1922
|
+
operations: [...permission.operations],
|
|
1923
|
+
allOperations: permission.operations.length === 0,
|
|
1924
|
+
})) ?? [];
|
|
1925
|
+
}
|
|
1926
|
+
|
|
1868
1927
|
function listDefinitionsResult(value: readonly WorkflowDefinition[] | ListWorkflowProviderDefinitionsResponse): ListWorkflowProviderDefinitionsResponse {
|
|
1869
1928
|
return "definitions" in value ? value : { definitions: value };
|
|
1870
1929
|
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { Request } from "./api.ts";
|
|
2
|
-
|
|
3
|
-
export function hostInvocationContext(requestOrToken: Request | string) {
|
|
4
|
-
const invocationToken = (typeof requestOrToken === "string" ? requestOrToken : requestOrToken.invocationToken).trim();
|
|
5
|
-
if (typeof requestOrToken === "string") {
|
|
6
|
-
return { invocationToken };
|
|
7
|
-
}
|
|
8
|
-
const providerName = stringValue(requestOrToken.workflow.providerName) || stringValue(requestOrToken.workflow.provider);
|
|
9
|
-
const runId = stringValue(requestOrToken.workflow.runId);
|
|
10
|
-
return providerName && runId
|
|
11
|
-
? { invocationToken, workflow: { provider: providerName, providerName, runId } }
|
|
12
|
-
: { invocationToken };
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
const stringValue = (value: unknown) => (typeof value === "string" ? value.trim() : "");
|