@plurnk/plurnk-contracts 8.0.0 → 10.0.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/.env.defaults +1 -19
- package/README.md +5 -6
- package/SPEC.md +100 -65
- package/dist/schema/DaemonNotificationEnvelope.json +602 -0
- package/dist/schema/FunctionalityCandidate.json +4 -0
- package/dist/schema/FunctionalityDiscoverQuery.json +12 -0
- package/dist/schema/FunctionalityDiscoverResult.json +10 -0
- package/dist/schema/FunctionalityListQuery.json +33 -0
- package/dist/schema/FunctionalityListResult.json +16 -1
- package/dist/schema/McpServerDefinition.json +1 -1
- package/dist/schema/ModelCatalogPage.json +9 -0
- package/dist/schema/PlurnkStatement.json +42 -2
- package/dist/schema/ProposalProjection.json +0 -4
- package/dist/schema/ProviderAccounting.json +3 -3
- package/dist/schema/ProviderCost.json +1 -1
- package/dist/schema/ProviderRequestAccounting.json +3 -3
- package/dist/schema/ProviderUsage.json +1 -1
- package/dist/src/ActorIdentity.d.ts +26 -0
- package/dist/src/ActorIdentity.d.ts.map +1 -0
- package/dist/src/ActorIdentity.js +179 -0
- package/dist/src/ActorIdentity.js.map +1 -0
- package/dist/src/Application.d.ts +58 -125
- package/dist/src/Application.d.ts.map +1 -1
- package/dist/src/Application.js +372 -80
- package/dist/src/Application.js.map +1 -1
- package/dist/src/ApplicationNotifications.d.ts +77 -24
- package/dist/src/ApplicationNotifications.d.ts.map +1 -1
- package/dist/src/ApplicationNotifications.js +45 -9
- package/dist/src/ApplicationNotifications.js.map +1 -1
- package/dist/src/ApplicationPort.d.ts +53 -13
- package/dist/src/ApplicationPort.d.ts.map +1 -1
- package/dist/src/ApplicationPort.js +1 -1
- package/dist/src/ApplicationPort.js.map +1 -1
- package/dist/src/ApplicationStream.d.ts +2 -2
- package/dist/src/ApplicationStream.d.ts.map +1 -1
- package/dist/src/ApplicationStream.js.map +1 -1
- package/dist/src/CollectionCommand.d.ts +33 -0
- package/dist/src/CollectionCommand.d.ts.map +1 -0
- package/dist/src/CollectionCommand.js +277 -0
- package/dist/src/CollectionCommand.js.map +1 -0
- package/dist/src/Functionality.d.ts +7 -2
- package/dist/src/Functionality.d.ts.map +1 -1
- package/dist/src/Functionality.js.map +1 -1
- package/dist/src/HttpOrigin.d.ts +79 -10
- package/dist/src/HttpOrigin.d.ts.map +1 -1
- package/dist/src/HttpOrigin.js +286 -44
- package/dist/src/HttpOrigin.js.map +1 -1
- package/dist/src/HttpPort.d.ts +35 -0
- package/dist/src/HttpPort.d.ts.map +1 -0
- package/dist/src/HttpPort.js +106 -0
- package/dist/src/HttpPort.js.map +1 -0
- package/dist/src/InteractiveCommands.d.ts +96 -0
- package/dist/src/InteractiveCommands.d.ts.map +1 -0
- package/dist/src/InteractiveCommands.js +409 -0
- package/dist/src/InteractiveCommands.js.map +1 -0
- package/dist/src/LogRow.d.ts +1 -1
- package/dist/src/LogRow.js +1 -1
- package/dist/src/LogRow.js.map +1 -1
- package/dist/src/McpWireTool.d.ts +27 -0
- package/dist/src/McpWireTool.d.ts.map +1 -0
- package/dist/src/McpWireTool.js +30 -0
- package/dist/src/McpWireTool.js.map +1 -0
- package/dist/src/OAuthClient.d.ts +64 -0
- package/dist/src/OAuthClient.d.ts.map +1 -0
- package/dist/src/OAuthClient.js +226 -0
- package/dist/src/OAuthClient.js.map +1 -0
- package/dist/src/ScheduleCommand.d.ts +60 -0
- package/dist/src/ScheduleCommand.d.ts.map +1 -0
- package/dist/src/ScheduleCommand.js +677 -0
- package/dist/src/ScheduleCommand.js.map +1 -0
- package/dist/src/SessionProjection.d.ts +91 -0
- package/dist/src/SessionProjection.d.ts.map +1 -0
- package/dist/src/SessionProjection.js +223 -0
- package/dist/src/SessionProjection.js.map +1 -0
- package/dist/src/Validator.d.ts +4 -3
- package/dist/src/Validator.d.ts.map +1 -1
- package/dist/src/Validator.js +27 -17
- package/dist/src/Validator.js.map +1 -1
- package/dist/src/index.d.ts +11 -5
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +9 -4
- package/dist/src/index.js.map +1 -1
- package/dist/src/types.generated.d.ts +814 -566
- package/dist/src/types.generated.d.ts.map +1 -1
- package/dist/src/types.generated.js.map +1 -1
- package/dist/src/types.js +1 -1
- package/dist/src/types.js.map +1 -1
- package/package.json +3 -2
- package/dist/schema/ApplicationOperationEvent.json +0 -27
- package/dist/schema/CapabilityDescriptor.json +0 -28
- package/dist/schema/CapabilityPolicy.json +0 -22
- package/dist/schema/CapabilityProjection.json +0 -14
- package/dist/schema/CapabilitySelector.json +0 -29
- package/dist/src/CapabilityAdmission.d.ts +0 -11
- package/dist/src/CapabilityAdmission.d.ts.map +0 -1
- package/dist/src/CapabilityAdmission.js +0 -108
- package/dist/src/CapabilityAdmission.js.map +0 -1
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "https://schemas.plurnk.xyz/v0/FunctionalityListQuery.json",
|
|
4
|
+
"title": "FunctionalityListQuery",
|
|
5
|
+
"description": "A family-neutral bounded filter and pagination query over workspace or session Functionality definitions.",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"additionalProperties": false,
|
|
8
|
+
"properties": {
|
|
9
|
+
"query": {
|
|
10
|
+
"description": "Case-insensitive substring filter over alias, provenance, and non-secret definition metadata.",
|
|
11
|
+
"type": "string",
|
|
12
|
+
"maxLength": 256
|
|
13
|
+
},
|
|
14
|
+
"state": {
|
|
15
|
+
"description": "Filter by current preparation or enablement state.",
|
|
16
|
+
"enum": ["disabled", "dormant", "active", "unavailable", "authorization-required"]
|
|
17
|
+
},
|
|
18
|
+
"origin": {
|
|
19
|
+
"description": "Filter by definition ownership.",
|
|
20
|
+
"enum": ["service", "workspace", "session"]
|
|
21
|
+
},
|
|
22
|
+
"offset": {
|
|
23
|
+
"type": "integer",
|
|
24
|
+
"minimum": 0,
|
|
25
|
+
"maximum": 9007199254740991
|
|
26
|
+
},
|
|
27
|
+
"limit": {
|
|
28
|
+
"type": "integer",
|
|
29
|
+
"minimum": 1,
|
|
30
|
+
"maximum": 100
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -4,12 +4,27 @@
|
|
|
4
4
|
"title": "FunctionalityListResult",
|
|
5
5
|
"type": "object",
|
|
6
6
|
"additionalProperties": false,
|
|
7
|
-
"required": ["family", "definitions"],
|
|
7
|
+
"required": ["family", "definitions", "offset", "total"],
|
|
8
8
|
"properties": {
|
|
9
9
|
"family": { "type": "string", "minLength": 1 },
|
|
10
10
|
"definitions": {
|
|
11
11
|
"type": "array",
|
|
12
12
|
"items": { "$ref": "https://schemas.plurnk.xyz/v0/FunctionalityDefinitionState.json" }
|
|
13
|
+
},
|
|
14
|
+
"offset": {
|
|
15
|
+
"type": "integer",
|
|
16
|
+
"minimum": 0,
|
|
17
|
+
"maximum": 9007199254740991
|
|
18
|
+
},
|
|
19
|
+
"total": {
|
|
20
|
+
"type": "integer",
|
|
21
|
+
"minimum": 0,
|
|
22
|
+
"maximum": 9007199254740991
|
|
23
|
+
},
|
|
24
|
+
"nextOffset": {
|
|
25
|
+
"type": "integer",
|
|
26
|
+
"minimum": 1,
|
|
27
|
+
"maximum": 9007199254740991
|
|
13
28
|
}
|
|
14
29
|
}
|
|
15
30
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
3
|
"$id": "https://schemas.plurnk.xyz/v0/McpServerDefinition.json",
|
|
4
4
|
"title": "McpServerDefinition",
|
|
5
|
-
"description": "One complete MCP connection definition. Configuration sources supply it; workspace management persists it without
|
|
5
|
+
"description": "One complete MCP connection definition. Configuration sources supply it; workspace management persists it without rewriting configuration files.",
|
|
6
6
|
"oneOf": [
|
|
7
7
|
{
|
|
8
8
|
"$ref": "#/$defs/stdio"
|
|
@@ -28,6 +28,15 @@
|
|
|
28
28
|
"type": "integer",
|
|
29
29
|
"minimum": 1,
|
|
30
30
|
"maximum": 9007199254740991
|
|
31
|
+
},
|
|
32
|
+
"providers": {
|
|
33
|
+
"description": "Sorted unique provider ids available in this availability-scoped catalog.",
|
|
34
|
+
"type": "array",
|
|
35
|
+
"uniqueItems": true,
|
|
36
|
+
"items": {
|
|
37
|
+
"type": "string",
|
|
38
|
+
"minLength": 1
|
|
39
|
+
}
|
|
31
40
|
}
|
|
32
41
|
},
|
|
33
42
|
"$defs": {
|
|
@@ -356,6 +356,12 @@
|
|
|
356
356
|
"body": {
|
|
357
357
|
"$ref": "#/$defs/SendBodyOrNull"
|
|
358
358
|
},
|
|
359
|
+
"actor": {
|
|
360
|
+
"type": [
|
|
361
|
+
"string",
|
|
362
|
+
"null"
|
|
363
|
+
]
|
|
364
|
+
},
|
|
359
365
|
"position": {
|
|
360
366
|
"$ref": "#/$defs/PositionRef"
|
|
361
367
|
}
|
|
@@ -468,6 +474,17 @@
|
|
|
468
474
|
"null"
|
|
469
475
|
]
|
|
470
476
|
},
|
|
477
|
+
"env": {
|
|
478
|
+
"description": "Optional per-invocation environment variables (`{ [name: string]: string }`).",
|
|
479
|
+
"type": "object",
|
|
480
|
+
"propertyNames": {
|
|
481
|
+
"pattern": "^[A-Za-z_][A-Za-z0-9_]*$"
|
|
482
|
+
},
|
|
483
|
+
"additionalProperties": {
|
|
484
|
+
"type": "string"
|
|
485
|
+
},
|
|
486
|
+
"tsType": "Readonly<Record<string, string>>"
|
|
487
|
+
},
|
|
471
488
|
"lineMarker": {
|
|
472
489
|
"$ref": "#/$defs/LineMarkerOrNull"
|
|
473
490
|
},
|
|
@@ -554,8 +571,7 @@
|
|
|
554
571
|
"description": "The selection matcher lifted from the `pattern` option ({§parse-recovery}); null when omitted."
|
|
555
572
|
},
|
|
556
573
|
"body": {
|
|
557
|
-
"type":
|
|
558
|
-
"description": "A `log:///` `kill` carries its optional distillation, kept as the model's own `note` row ({§log-kill-scope}). Other `kill` statements take no body; their matcher rides on the `pattern` option ({§parse-recovery})."
|
|
574
|
+
"type": "null"
|
|
559
575
|
},
|
|
560
576
|
"position": {
|
|
561
577
|
"$ref": "#/$defs/PositionRef"
|
|
@@ -589,6 +605,18 @@
|
|
|
589
605
|
"body": {
|
|
590
606
|
"type": "string"
|
|
591
607
|
},
|
|
608
|
+
"persona": {
|
|
609
|
+
"type": "string",
|
|
610
|
+
"minLength": 1
|
|
611
|
+
},
|
|
612
|
+
"model": {
|
|
613
|
+
"type": "string",
|
|
614
|
+
"minLength": 1
|
|
615
|
+
},
|
|
616
|
+
"effort": {
|
|
617
|
+
"type": "string",
|
|
618
|
+
"minLength": 1
|
|
619
|
+
},
|
|
592
620
|
"position": {
|
|
593
621
|
"$ref": "#/$defs/PositionRef"
|
|
594
622
|
}
|
|
@@ -621,6 +649,18 @@
|
|
|
621
649
|
"body": {
|
|
622
650
|
"type": "string"
|
|
623
651
|
},
|
|
652
|
+
"persona": {
|
|
653
|
+
"type": "string",
|
|
654
|
+
"minLength": 1
|
|
655
|
+
},
|
|
656
|
+
"model": {
|
|
657
|
+
"type": "string",
|
|
658
|
+
"minLength": 1
|
|
659
|
+
},
|
|
660
|
+
"effort": {
|
|
661
|
+
"type": "string",
|
|
662
|
+
"minLength": 1
|
|
663
|
+
},
|
|
624
664
|
"position": {
|
|
625
665
|
"$ref": "#/$defs/PositionRef"
|
|
626
666
|
}
|
|
@@ -117,10 +117,6 @@
|
|
|
117
117
|
"disposition": {
|
|
118
118
|
"$ref": "https://schemas.plurnk.xyz/v0/ProposalDisposition.json"
|
|
119
119
|
},
|
|
120
|
-
"selector": {
|
|
121
|
-
"description": "The capability selector for the proposed operation, persisted on allow_always / reject_always.",
|
|
122
|
-
"$ref": "https://schemas.plurnk.xyz/v0/CapabilitySelector.json"
|
|
123
|
-
},
|
|
124
120
|
"subject": {
|
|
125
121
|
"description": "Structured ACP v2 permission subject for the proposed operation.",
|
|
126
122
|
"oneOf": [
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
-
"$id": "https://schemas.plurnk.xyz/ProviderAccounting.json",
|
|
3
|
+
"$id": "https://schemas.plurnk.xyz/v0/ProviderAccounting.json",
|
|
4
4
|
"title": "ProviderAccounting",
|
|
5
5
|
"description": "Ordered physical provider-request evidence and its deterministic aggregate projection.",
|
|
6
6
|
"type": "object",
|
|
@@ -9,11 +9,11 @@
|
|
|
9
9
|
"properties": {
|
|
10
10
|
"requests": {
|
|
11
11
|
"type": "array",
|
|
12
|
-
"items": { "$ref": "https://schemas.plurnk.xyz/ProviderRequestAccounting.json" }
|
|
12
|
+
"items": { "$ref": "https://schemas.plurnk.xyz/v0/ProviderRequestAccounting.json" }
|
|
13
13
|
},
|
|
14
14
|
"usage": {
|
|
15
15
|
"oneOf": [
|
|
16
|
-
{ "$ref": "https://schemas.plurnk.xyz/ProviderUsage.json" },
|
|
16
|
+
{ "$ref": "https://schemas.plurnk.xyz/v0/ProviderUsage.json" },
|
|
17
17
|
{ "type": "null" }
|
|
18
18
|
]
|
|
19
19
|
},
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
-
"$id": "https://schemas.plurnk.xyz/ProviderCost.json",
|
|
3
|
+
"$id": "https://schemas.plurnk.xyz/v0/ProviderCost.json",
|
|
4
4
|
"title": "ProviderCost",
|
|
5
5
|
"description": "Normalized monetary evidence for one physical provider request. Unknown is never represented as zero.",
|
|
6
6
|
"oneOf": [
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
-
"$id": "https://schemas.plurnk.xyz/ProviderRequestAccounting.json",
|
|
3
|
+
"$id": "https://schemas.plurnk.xyz/v0/ProviderRequestAccounting.json",
|
|
4
4
|
"title": "ProviderRequestAccounting",
|
|
5
5
|
"description": "The normalized accounting disposition of one physical provider request.",
|
|
6
6
|
"type": "object",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"model": { "type": "string", "minLength": 1 },
|
|
12
12
|
"outcome": { "enum": ["response", "error"] },
|
|
13
13
|
"status": { "type": "integer", "minimum": 100, "maximum": 599 },
|
|
14
|
-
"usage": { "$ref": "https://schemas.plurnk.xyz/ProviderUsage.json" },
|
|
15
|
-
"cost": { "$ref": "https://schemas.plurnk.xyz/ProviderCost.json" }
|
|
14
|
+
"usage": { "$ref": "https://schemas.plurnk.xyz/v0/ProviderUsage.json" },
|
|
15
|
+
"cost": { "$ref": "https://schemas.plurnk.xyz/v0/ProviderCost.json" }
|
|
16
16
|
}
|
|
17
17
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
-
"$id": "https://schemas.plurnk.xyz/ProviderUsage.json",
|
|
3
|
+
"$id": "https://schemas.plurnk.xyz/v0/ProviderUsage.json",
|
|
4
4
|
"title": "ProviderUsage",
|
|
5
5
|
"description": "Token quantities. Physical-request instances enforce their partition identities. ProviderAccounting distinguishes complete usage from knownUsage subtotals. Omitted fields are unknown; explicit zero is observed or exactly derived.",
|
|
6
6
|
"type": "object",
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export type ExteriorActorScheme = "acp" | "mcp";
|
|
2
|
+
export interface ExteriorActor {
|
|
3
|
+
readonly name: string;
|
|
4
|
+
readonly scheme: ExteriorActorScheme;
|
|
5
|
+
readonly uri: string;
|
|
6
|
+
}
|
|
7
|
+
export declare const isDefaultExteriorActor: (name: string | null | undefined) => boolean;
|
|
8
|
+
/**
|
|
9
|
+
* Parse and normalize an exterior actor identifier (bare name like `"hazool17"` or
|
|
10
|
+
* authority-only exterior URI like `"acp://hazool17"` / `"mcp://bridge"`).
|
|
11
|
+
* Rejects internal schemes (`session://`, `message://`, `log://`, etc.), `_plurnk`,
|
|
12
|
+
* path/query/fragment/userinfo/port components, whitespace, and malformed encodings.
|
|
13
|
+
*/
|
|
14
|
+
export declare const parseExteriorActor: (raw: string, defaultScheme?: ExteriorActorScheme) => ExteriorActor | null;
|
|
15
|
+
/**
|
|
16
|
+
* Compare a caller-requested actor (bare name or exterior URI) against an
|
|
17
|
+
* authenticated credential subject (`admission.subject`).
|
|
18
|
+
*/
|
|
19
|
+
export declare const actorsMatch: (requested: string, authenticatedSubject: string) => boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Extract the non-default causal actor name from a Plurnk message source or address URI
|
|
22
|
+
* (`acp://<actor>[/...]`, `mcp://<actor>[/...]`, `session://<worker>[/...]`, or `message://<session>/<actor>_<seq>`).
|
|
23
|
+
* Returns `undefined` for unnamed default exterior actors (`operator`, `anonymous`, `client`, `owner`) or `_plurnk`.
|
|
24
|
+
*/
|
|
25
|
+
export declare const extractActor: (sourceOrAddress: string | null | undefined) => string | undefined;
|
|
26
|
+
//# sourceMappingURL=ActorIdentity.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ActorIdentity.d.ts","sourceRoot":"","sources":["../../src/ActorIdentity.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,mBAAmB,GAAG,KAAK,GAAG,KAAK,CAAC;AAEhD,MAAM,WAAW,aAAa;IAC1B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,mBAAmB,CAAC;IACrC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;CACxB;AA8BD,eAAO,MAAM,sBAAsB,SAAU,MAAM,GAAG,IAAI,GAAG,SAAS,KAAG,OAGxE,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,QACtB,MAAM,kBACI,mBAAmB,KACnC,aAAa,GAAG,IA2ClB,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,WAAW,cAAe,MAAM,wBAAwB,MAAM,KAAG,OAS7E,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,YAAY,oBAAqB,MAAM,GAAG,IAAI,GAAG,SAAS,KAAG,MAAM,GAAG,SAsElF,CAAC"}
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
// {§contract-representations} {§client-session-status} Runtime-neutral exterior actor parsing, normalization, and attribution extraction.
|
|
2
|
+
const UNNAMED_EXTERIOR_ACTORS = new Set([
|
|
3
|
+
"",
|
|
4
|
+
"operator",
|
|
5
|
+
"anonymous",
|
|
6
|
+
"client",
|
|
7
|
+
"owner",
|
|
8
|
+
]);
|
|
9
|
+
const RESERVED_ACTOR_NAMES = new Set([
|
|
10
|
+
"_plurnk",
|
|
11
|
+
".",
|
|
12
|
+
"..",
|
|
13
|
+
]);
|
|
14
|
+
const EXTERIOR_ACTOR_SCHEMES = new Set(["acp", "mcp"]);
|
|
15
|
+
// Bare exterior actor names forbid whitespace, ASCII control chars, and URI structural delimiters.
|
|
16
|
+
const isValidActorName = (value) => {
|
|
17
|
+
if (value.length === 0 || value.length > 256)
|
|
18
|
+
return false;
|
|
19
|
+
if (value === "_plurnk" || value === "." || value === "..")
|
|
20
|
+
return false;
|
|
21
|
+
if (!value.isWellFormed())
|
|
22
|
+
return false;
|
|
23
|
+
for (let i = 0; i < value.length; i += 1) {
|
|
24
|
+
const code = value.charCodeAt(i);
|
|
25
|
+
if (code <= 0x20 || code === 0x7f)
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
return !/[/?#\\]/u.test(value);
|
|
29
|
+
};
|
|
30
|
+
export const isDefaultExteriorActor = (name) => {
|
|
31
|
+
if (typeof name !== "string")
|
|
32
|
+
return true;
|
|
33
|
+
return UNNAMED_EXTERIOR_ACTORS.has(name.trim());
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Parse and normalize an exterior actor identifier (bare name like `"hazool17"` or
|
|
37
|
+
* authority-only exterior URI like `"acp://hazool17"` / `"mcp://bridge"`).
|
|
38
|
+
* Rejects internal schemes (`session://`, `message://`, `log://`, etc.), `_plurnk`,
|
|
39
|
+
* path/query/fragment/userinfo/port components, whitespace, and malformed encodings.
|
|
40
|
+
*/
|
|
41
|
+
export const parseExteriorActor = (raw, defaultScheme = "acp") => {
|
|
42
|
+
const trimmed = raw.trim();
|
|
43
|
+
if (trimmed.length === 0 || RESERVED_ACTOR_NAMES.has(trimmed))
|
|
44
|
+
return null;
|
|
45
|
+
const schemeMatch = /^([a-z][a-z0-9+.-]*):\/\//iu.exec(trimmed);
|
|
46
|
+
if (schemeMatch !== null) {
|
|
47
|
+
const scheme = (schemeMatch[1] ?? "").toLowerCase();
|
|
48
|
+
if (!EXTERIOR_ACTOR_SCHEMES.has(scheme))
|
|
49
|
+
return null;
|
|
50
|
+
const rest = trimmed.slice(schemeMatch[0].length);
|
|
51
|
+
// Authority-only: reject pathname (except optional trailing slash), query, fragment, userinfo, or port.
|
|
52
|
+
const authority = rest.endsWith("/") ? rest.slice(0, -1) : rest;
|
|
53
|
+
if (authority.length === 0 ||
|
|
54
|
+
authority.includes("/") ||
|
|
55
|
+
authority.includes("?") ||
|
|
56
|
+
authority.includes("#") ||
|
|
57
|
+
authority.includes("@") ||
|
|
58
|
+
authority.includes(":")) {
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
let decoded;
|
|
62
|
+
try {
|
|
63
|
+
decoded = decodeURIComponent(authority);
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
if (!isValidActorName(decoded))
|
|
69
|
+
return null;
|
|
70
|
+
const typedScheme = scheme === "mcp" ? "mcp" : "acp";
|
|
71
|
+
return {
|
|
72
|
+
name: decoded,
|
|
73
|
+
scheme: typedScheme,
|
|
74
|
+
uri: `${typedScheme}://${encodeURIComponent(decoded)}`,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
if (trimmed.includes("://"))
|
|
78
|
+
return null;
|
|
79
|
+
if (!isValidActorName(trimmed))
|
|
80
|
+
return null;
|
|
81
|
+
return {
|
|
82
|
+
name: trimmed,
|
|
83
|
+
scheme: defaultScheme,
|
|
84
|
+
uri: `${defaultScheme}://${encodeURIComponent(trimmed)}`,
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
/**
|
|
88
|
+
* Compare a caller-requested actor (bare name or exterior URI) against an
|
|
89
|
+
* authenticated credential subject (`admission.subject`).
|
|
90
|
+
*/
|
|
91
|
+
export const actorsMatch = (requested, authenticatedSubject) => {
|
|
92
|
+
const reqTrimmed = requested.trim();
|
|
93
|
+
const subTrimmed = authenticatedSubject.trim();
|
|
94
|
+
if (reqTrimmed.length === 0 || subTrimmed.length === 0)
|
|
95
|
+
return false;
|
|
96
|
+
const reqParsed = parseExteriorActor(reqTrimmed);
|
|
97
|
+
const subParsed = parseExteriorActor(subTrimmed);
|
|
98
|
+
const reqName = reqParsed?.name ?? reqTrimmed;
|
|
99
|
+
const subName = subParsed?.name ?? subTrimmed;
|
|
100
|
+
return reqName === subName;
|
|
101
|
+
};
|
|
102
|
+
/**
|
|
103
|
+
* Extract the non-default causal actor name from a Plurnk message source or address URI
|
|
104
|
+
* (`acp://<actor>[/...]`, `mcp://<actor>[/...]`, `session://<worker>[/...]`, or `message://<session>/<actor>_<seq>`).
|
|
105
|
+
* Returns `undefined` for unnamed default exterior actors (`operator`, `anonymous`, `client`, `owner`) or `_plurnk`.
|
|
106
|
+
*/
|
|
107
|
+
export const extractActor = (sourceOrAddress) => {
|
|
108
|
+
if (typeof sourceOrAddress !== "string" || sourceOrAddress.length === 0)
|
|
109
|
+
return undefined;
|
|
110
|
+
const acpMatch = /^acp:\/\/([^/?#]+)/u.exec(sourceOrAddress);
|
|
111
|
+
if (acpMatch !== null) {
|
|
112
|
+
try {
|
|
113
|
+
const principal = decodeURIComponent(acpMatch[1] ?? "");
|
|
114
|
+
if (principal.length > 0 && !UNNAMED_EXTERIOR_ACTORS.has(principal) && principal !== "_plurnk") {
|
|
115
|
+
return principal;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
catch {
|
|
119
|
+
// fall through
|
|
120
|
+
}
|
|
121
|
+
return undefined;
|
|
122
|
+
}
|
|
123
|
+
const mcpMatch = /^mcp:\/\/([^/?#]+)/u.exec(sourceOrAddress);
|
|
124
|
+
if (mcpMatch !== null) {
|
|
125
|
+
try {
|
|
126
|
+
const principal = decodeURIComponent(mcpMatch[1] ?? "");
|
|
127
|
+
if (principal.length > 0 && !UNNAMED_EXTERIOR_ACTORS.has(principal) && principal !== "_plurnk") {
|
|
128
|
+
return principal;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
catch {
|
|
132
|
+
// fall through
|
|
133
|
+
}
|
|
134
|
+
return undefined;
|
|
135
|
+
}
|
|
136
|
+
const sessionMatch = /^session:\/\/([^/?#]+)/u.exec(sourceOrAddress);
|
|
137
|
+
if (sessionMatch !== null) {
|
|
138
|
+
try {
|
|
139
|
+
const worker = decodeURIComponent(sessionMatch[1] ?? "");
|
|
140
|
+
if (worker.length > 0 && worker !== "_plurnk")
|
|
141
|
+
return worker;
|
|
142
|
+
}
|
|
143
|
+
catch {
|
|
144
|
+
// fall through
|
|
145
|
+
}
|
|
146
|
+
return undefined;
|
|
147
|
+
}
|
|
148
|
+
const messageMatch = /^message:\/\/[^/?#]+\/([^/?#]+)_([0-9a-zA-Z]{2,5})$/u.exec(sourceOrAddress);
|
|
149
|
+
if (messageMatch !== null) {
|
|
150
|
+
try {
|
|
151
|
+
const principal = decodeURIComponent(messageMatch[1] ?? "");
|
|
152
|
+
if (principal.length > 0 && !UNNAMED_EXTERIOR_ACTORS.has(principal) && principal !== "_plurnk") {
|
|
153
|
+
return principal;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
catch {
|
|
157
|
+
// fall through
|
|
158
|
+
}
|
|
159
|
+
return undefined;
|
|
160
|
+
}
|
|
161
|
+
const schedulePathMatch = /^schedule:\/\/\/([^?#]+)$/u.exec(sourceOrAddress.split(/[?#]/u, 1)[0] ?? "");
|
|
162
|
+
if (schedulePathMatch !== null) {
|
|
163
|
+
const segments = (schedulePathMatch[1] ?? "").split("/").filter((s) => s.length > 0);
|
|
164
|
+
const rawAlias = segments[0] === "rules" ? segments[1] : segments[0];
|
|
165
|
+
if (rawAlias !== undefined && rawAlias.length > 0) {
|
|
166
|
+
try {
|
|
167
|
+
const alias = decodeURIComponent(rawAlias);
|
|
168
|
+
if (alias.length > 0 && !UNNAMED_EXTERIOR_ACTORS.has(alias) && alias !== "_plurnk") {
|
|
169
|
+
return alias;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
catch {
|
|
173
|
+
// fall through
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
return undefined;
|
|
178
|
+
};
|
|
179
|
+
//# sourceMappingURL=ActorIdentity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ActorIdentity.js","sourceRoot":"","sources":["../../src/ActorIdentity.ts"],"names":[],"mappings":"AAAA,0IAA0I;AAU1I,MAAM,uBAAuB,GAAwB,IAAI,GAAG,CAAC;IACzD,EAAE;IACF,UAAU;IACV,WAAW;IACX,QAAQ;IACR,OAAO;CACV,CAAC,CAAC;AAEH,MAAM,oBAAoB,GAAwB,IAAI,GAAG,CAAC;IACtD,SAAS;IACT,GAAG;IACH,IAAI;CACP,CAAC,CAAC;AAEH,MAAM,sBAAsB,GAAwB,IAAI,GAAG,CAAC,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC;AAE5E,mGAAmG;AACnG,MAAM,gBAAgB,GAAG,CAAC,KAAa,EAAW,EAAE;IAChD,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,IAAI,KAAK,CAAC,MAAM,GAAG,GAAG;QAAE,OAAO,KAAK,CAAC;IAC3D,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,GAAG,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,KAAK,CAAC;IACzE,IAAI,CAAC,KAAK,CAAC,YAAY,EAAE;QAAE,OAAO,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AAC;gBAC7F,OAAO,SAAS,CAAC;YACrB,CAAC;QACL,CAAC;QAAC,MAAM,CAAC;YACL,eAAe;QACnB,CAAC;QACD,OAAO,SAAS,CAAC;IACrB,CAAC;IAED,MAAM,iBAAiB,GAAG,4BAA4B,CAAC,IAAI,CAAC,eAAe,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;IACxG,IAAI,iBAAiB,KAAK,IAAI,EAAE,CAAC;QAC7B,MAAM,QAAQ,GAAG,CAAC,iBAAiB,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;QACrF,MAAM,QAAQ,GAAG,QAAQ,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;QACrE,IAAI,QAAQ,KAAK,SAAS,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAChD,IAAI,CAAC;gBACD,MAAM,KAAK,GAAG,kBAAkB,CAAC,QAAQ,CAAC,CAAC;gBAC3C,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,uBAAuB,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;oBACjF,OAAO,KAAK,CAAC;gBACjB,CAAC;YACL,CAAC;YAAC,MAAM,CAAC;gBACL,eAAe;YACnB,CAAC;QACL,CAAC;IACL,CAAC;IAED,OAAO,SAAS,CAAC;AACrB,CAAC,CAAC","sourcesContent":["// {§contract-representations} {§client-session-status} Runtime-neutral exterior actor parsing, normalization, and attribution extraction.\n\nexport type ExteriorActorScheme = \"acp\" | \"mcp\";\n\nexport interface ExteriorActor {\n readonly name: string;\n readonly scheme: ExteriorActorScheme;\n readonly uri: string;\n}\n\nconst UNNAMED_EXTERIOR_ACTORS: ReadonlySet<string> = new Set([\n \"\",\n \"operator\",\n \"anonymous\",\n \"client\",\n \"owner\",\n]);\n\nconst RESERVED_ACTOR_NAMES: ReadonlySet<string> = new Set([\n \"_plurnk\",\n \".\",\n \"..\",\n]);\n\nconst EXTERIOR_ACTOR_SCHEMES: ReadonlySet<string> = new Set([\"acp\", \"mcp\"]);\n\n// Bare exterior actor names forbid whitespace, ASCII control chars, and URI structural delimiters.\nconst isValidActorName = (value: string): boolean => {\n if (value.length === 0 || value.length > 256) return false;\n if (value === \"_plurnk\" || value === \".\" || value === \"..\") return false;\n if (!value.isWellFormed()) return false;\n for (let i = 0; i < value.length; i += 1) {\n const code = value.charCodeAt(i);\n if (code <= 0x20 || code === 0x7f) return false;\n }\n return !/[/?#\\\\]/u.test(value);\n};\n\nexport const isDefaultExteriorActor = (name: string | null | undefined): boolean => {\n if (typeof name !== \"string\") return true;\n return UNNAMED_EXTERIOR_ACTORS.has(name.trim());\n};\n\n/**\n * Parse and normalize an exterior actor identifier (bare name like `\"hazool17\"` or\n * authority-only exterior URI like `\"acp://hazool17\"` / `\"mcp://bridge\"`).\n * Rejects internal schemes (`session://`, `message://`, `log://`, etc.), `_plurnk`,\n * path/query/fragment/userinfo/port components, whitespace, and malformed encodings.\n */\nexport const parseExteriorActor = (\n raw: string,\n defaultScheme: ExteriorActorScheme = \"acp\",\n): ExteriorActor | null => {\n const trimmed = raw.trim();\n if (trimmed.length === 0 || RESERVED_ACTOR_NAMES.has(trimmed)) return null;\n\n const schemeMatch = /^([a-z][a-z0-9+.-]*):\\/\\//iu.exec(trimmed);\n if (schemeMatch !== null) {\n const scheme = (schemeMatch[1] ?? \"\").toLowerCase();\n if (!EXTERIOR_ACTOR_SCHEMES.has(scheme)) return null;\n const rest = trimmed.slice(schemeMatch[0].length);\n // Authority-only: reject pathname (except optional trailing slash), query, fragment, userinfo, or port.\n const authority = rest.endsWith(\"/\") ? rest.slice(0, -1) : rest;\n if (\n authority.length === 0 ||\n authority.includes(\"/\") ||\n authority.includes(\"?\") ||\n authority.includes(\"#\") ||\n authority.includes(\"@\") ||\n authority.includes(\":\")\n ) {\n return null;\n }\n let decoded: string;\n try {\n decoded = decodeURIComponent(authority);\n } catch {\n return null;\n }\n if (!isValidActorName(decoded)) return null;\n const typedScheme: ExteriorActorScheme = scheme === \"mcp\" ? \"mcp\" : \"acp\";\n return {\n name: decoded,\n scheme: typedScheme,\n uri: `${typedScheme}://${encodeURIComponent(decoded)}`,\n };\n }\n\n if (trimmed.includes(\"://\")) return null;\n if (!isValidActorName(trimmed)) return null;\n return {\n name: trimmed,\n scheme: defaultScheme,\n uri: `${defaultScheme}://${encodeURIComponent(trimmed)}`,\n };\n};\n\n/**\n * Compare a caller-requested actor (bare name or exterior URI) against an\n * authenticated credential subject (`admission.subject`).\n */\nexport const actorsMatch = (requested: string, authenticatedSubject: string): boolean => {\n const reqTrimmed = requested.trim();\n const subTrimmed = authenticatedSubject.trim();\n if (reqTrimmed.length === 0 || subTrimmed.length === 0) return false;\n const reqParsed = parseExteriorActor(reqTrimmed);\n const subParsed = parseExteriorActor(subTrimmed);\n const reqName = reqParsed?.name ?? reqTrimmed;\n const subName = subParsed?.name ?? subTrimmed;\n return reqName === subName;\n};\n\n/**\n * Extract the non-default causal actor name from a Plurnk message source or address URI\n * (`acp://<actor>[/...]`, `mcp://<actor>[/...]`, `session://<worker>[/...]`, or `message://<session>/<actor>_<seq>`).\n * Returns `undefined` for unnamed default exterior actors (`operator`, `anonymous`, `client`, `owner`) or `_plurnk`.\n */\nexport const extractActor = (sourceOrAddress: string | null | undefined): string | undefined => {\n if (typeof sourceOrAddress !== \"string\" || sourceOrAddress.length === 0) return undefined;\n\n const acpMatch = /^acp:\\/\\/([^/?#]+)/u.exec(sourceOrAddress);\n if (acpMatch !== null) {\n try {\n const principal = decodeURIComponent(acpMatch[1] ?? \"\");\n if (principal.length > 0 && !UNNAMED_EXTERIOR_ACTORS.has(principal) && principal !== \"_plurnk\") {\n return principal;\n }\n } catch {\n // fall through\n }\n return undefined;\n }\n\n const mcpMatch = /^mcp:\\/\\/([^/?#]+)/u.exec(sourceOrAddress);\n if (mcpMatch !== null) {\n try {\n const principal = decodeURIComponent(mcpMatch[1] ?? \"\");\n if (principal.length > 0 && !UNNAMED_EXTERIOR_ACTORS.has(principal) && principal !== \"_plurnk\") {\n return principal;\n }\n } catch {\n // fall through\n }\n return undefined;\n }\n\n const sessionMatch = /^session:\\/\\/([^/?#]+)/u.exec(sourceOrAddress);\n if (sessionMatch !== null) {\n try {\n const worker = decodeURIComponent(sessionMatch[1] ?? \"\");\n if (worker.length > 0 && worker !== \"_plurnk\") return worker;\n } catch {\n // fall through\n }\n return undefined;\n }\n\n const messageMatch = /^message:\\/\\/[^/?#]+\\/([^/?#]+)_([0-9a-zA-Z]{2,5})$/u.exec(sourceOrAddress);\n if (messageMatch !== null) {\n try {\n const principal = decodeURIComponent(messageMatch[1] ?? \"\");\n if (principal.length > 0 && !UNNAMED_EXTERIOR_ACTORS.has(principal) && principal !== \"_plurnk\") {\n return principal;\n }\n } catch {\n // fall through\n }\n return undefined;\n }\n\n const schedulePathMatch = /^schedule:\\/\\/\\/([^?#]+)$/u.exec(sourceOrAddress.split(/[?#]/u, 1)[0] ?? \"\");\n if (schedulePathMatch !== null) {\n const segments = (schedulePathMatch[1] ?? \"\").split(\"/\").filter((s) => s.length > 0);\n const rawAlias = segments[0] === \"rules\" ? segments[1] : segments[0];\n if (rawAlias !== undefined && rawAlias.length > 0) {\n try {\n const alias = decodeURIComponent(rawAlias);\n if (alias.length > 0 && !UNNAMED_EXTERIOR_ACTORS.has(alias) && alias !== \"_plurnk\") {\n return alias;\n }\n } catch {\n // fall through\n }\n }\n }\n\n return undefined;\n};\n"]}
|