@pinet/transport-core 0.1.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/LICENSE +21 -0
- package/README.md +47 -0
- package/dist/index.d.ts +93 -0
- package/dist/index.js +43 -0
- package/package.json +35 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Will Porcellini
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# @pinet/transport-core
|
|
2
|
+
|
|
3
|
+
Tiny transport-neutral contracts package for the `extensions` repo.
|
|
4
|
+
|
|
5
|
+
## What lives here
|
|
6
|
+
|
|
7
|
+
- canonical `InboundMessage` contract
|
|
8
|
+
- canonical `OutboundMessage` contract
|
|
9
|
+
- normalized outbound `content` shape for transport-aware rendering with plain-text fallback
|
|
10
|
+
- canonical `MessageAdapter` transport interface
|
|
11
|
+
|
|
12
|
+
## What stays out of scope
|
|
13
|
+
|
|
14
|
+
- broker state
|
|
15
|
+
- routing
|
|
16
|
+
- socket server/client logic
|
|
17
|
+
- Slack-specific normalization
|
|
18
|
+
- iMessage-specific AppleScript or readiness logic
|
|
19
|
+
- Pi extension commands/tools
|
|
20
|
+
|
|
21
|
+
This package exists to keep transport contracts transport-neutral while other packages decide how to route, persist, or render those messages.
|
|
22
|
+
|
|
23
|
+
## Publishing
|
|
24
|
+
|
|
25
|
+
This package is part of the full npm publish set tracked in
|
|
26
|
+
[`../plans/npm-publish.md`](../plans/npm-publish.md). Use the GitHub Actions
|
|
27
|
+
workflow's default dry-run/readiness path for validation; do not publish, tag, or
|
|
28
|
+
bump versions without explicit maintainer release approval.
|
|
29
|
+
|
|
30
|
+
## Outbound content rules
|
|
31
|
+
|
|
32
|
+
`OutboundMessage.text` remains the backward-compatible plain-text fallback and persistence body.
|
|
33
|
+
|
|
34
|
+
When richer transport-aware rendering is available, callers may also send `OutboundMessage.content`:
|
|
35
|
+
|
|
36
|
+
- `content.text`: canonical plain-text body
|
|
37
|
+
- `content.markdown`: optional markdown-friendly representation for markdown-capable text renderers or exports
|
|
38
|
+
- `content.slackBlocks`: optional prebuilt Slack Block Kit payload
|
|
39
|
+
|
|
40
|
+
Transports should prefer their transport-specific representation when present, then fall back to the canonical plain-text body:
|
|
41
|
+
|
|
42
|
+
1. transport-native content (`slackBlocks` for Slack)
|
|
43
|
+
2. plain `text`
|
|
44
|
+
|
|
45
|
+
`markdown` is supplementary for markdown-aware surfaces and should not replace the canonical plain-text body on plain-text transports like iMessage.
|
|
46
|
+
|
|
47
|
+
This keeps Slack, markdown-oriented exports, and plain-text sends aligned without requiring every caller to collapse everything into one presentation string upfront.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
export type RuntimeScopeSource = "explicit" | "compatibility";
|
|
2
|
+
export declare const DEFAULT_COMPATIBILITY_SCOPE_KEY = "default";
|
|
3
|
+
export interface WorkspaceInstallScopeCarrier {
|
|
4
|
+
provider: string;
|
|
5
|
+
source: RuntimeScopeSource;
|
|
6
|
+
compatibilityKey?: string;
|
|
7
|
+
workspaceId?: string;
|
|
8
|
+
installId?: string;
|
|
9
|
+
channelId?: string;
|
|
10
|
+
}
|
|
11
|
+
export interface InstanceScopeCarrier {
|
|
12
|
+
source: RuntimeScopeSource;
|
|
13
|
+
compatibilityKey?: string;
|
|
14
|
+
instanceId?: string;
|
|
15
|
+
instanceName?: string;
|
|
16
|
+
}
|
|
17
|
+
export interface RuntimeScopeCarrier {
|
|
18
|
+
workspace?: WorkspaceInstallScopeCarrier;
|
|
19
|
+
instance?: InstanceScopeCarrier;
|
|
20
|
+
}
|
|
21
|
+
export declare function buildCompatibilityWorkspaceScope(options: {
|
|
22
|
+
provider: string;
|
|
23
|
+
workspaceId?: string | null;
|
|
24
|
+
installId?: string | null;
|
|
25
|
+
channelId?: string | null;
|
|
26
|
+
compatibilityKey?: string | null;
|
|
27
|
+
}): WorkspaceInstallScopeCarrier;
|
|
28
|
+
export declare function buildCompatibilityInstanceScope(options?: {
|
|
29
|
+
instanceId?: string | null;
|
|
30
|
+
instanceName?: string | null;
|
|
31
|
+
compatibilityKey?: string | null;
|
|
32
|
+
}): InstanceScopeCarrier;
|
|
33
|
+
export declare function buildRuntimeScopeCarrier(options: {
|
|
34
|
+
workspace?: WorkspaceInstallScopeCarrier | null;
|
|
35
|
+
instance?: InstanceScopeCarrier | null;
|
|
36
|
+
}): RuntimeScopeCarrier | undefined;
|
|
37
|
+
export interface InboundMessage {
|
|
38
|
+
source: string;
|
|
39
|
+
threadId: string;
|
|
40
|
+
channel: string;
|
|
41
|
+
userId: string;
|
|
42
|
+
userName?: string;
|
|
43
|
+
text: string;
|
|
44
|
+
timestamp: string;
|
|
45
|
+
isChannelMention?: boolean;
|
|
46
|
+
metadata?: Record<string, unknown>;
|
|
47
|
+
scope?: RuntimeScopeCarrier;
|
|
48
|
+
}
|
|
49
|
+
export interface NormalizedMessageContent {
|
|
50
|
+
text: string;
|
|
51
|
+
markdown?: string;
|
|
52
|
+
/**
|
|
53
|
+
* Compatibility/native-rendering escape hatch for Slack Block Kit payloads.
|
|
54
|
+
* This remains intentionally Slack-shaped for the current publish-readiness
|
|
55
|
+
* track while a future transport-neutral rich-content model is considered.
|
|
56
|
+
*/
|
|
57
|
+
slackBlocks?: ReadonlyArray<Record<string, unknown>>;
|
|
58
|
+
}
|
|
59
|
+
export interface OutboundMessage {
|
|
60
|
+
threadId: string;
|
|
61
|
+
channel: string;
|
|
62
|
+
text: string;
|
|
63
|
+
content?: NormalizedMessageContent;
|
|
64
|
+
blocks?: ReadonlyArray<Record<string, unknown>>;
|
|
65
|
+
agentName?: string;
|
|
66
|
+
agentEmoji?: string;
|
|
67
|
+
agentOwnerToken?: string;
|
|
68
|
+
metadata?: Record<string, unknown>;
|
|
69
|
+
scope?: RuntimeScopeCarrier;
|
|
70
|
+
}
|
|
71
|
+
export interface AdapterThreadClaimEffect {
|
|
72
|
+
threadId: string;
|
|
73
|
+
channel?: string;
|
|
74
|
+
}
|
|
75
|
+
export interface AdapterCapabilityEffects {
|
|
76
|
+
claimThread?: AdapterThreadClaimEffect | ReadonlyArray<AdapterThreadClaimEffect>;
|
|
77
|
+
}
|
|
78
|
+
export interface AdapterCapabilityRequest {
|
|
79
|
+
capability: string;
|
|
80
|
+
params: Record<string, unknown>;
|
|
81
|
+
}
|
|
82
|
+
export interface AdapterCapabilityResult {
|
|
83
|
+
result: Record<string, unknown>;
|
|
84
|
+
effects?: AdapterCapabilityEffects;
|
|
85
|
+
}
|
|
86
|
+
export interface MessageAdapter {
|
|
87
|
+
name: string;
|
|
88
|
+
connect(): Promise<void>;
|
|
89
|
+
disconnect(): Promise<void>;
|
|
90
|
+
onInbound(handler: (msg: InboundMessage) => void): void;
|
|
91
|
+
send(msg: OutboundMessage): Promise<void>;
|
|
92
|
+
invokeCapability?(request: AdapterCapabilityRequest): Promise<AdapterCapabilityResult>;
|
|
93
|
+
}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export const DEFAULT_COMPATIBILITY_SCOPE_KEY = "default";
|
|
2
|
+
function normalizeScopeValue(value) {
|
|
3
|
+
const trimmed = value?.trim();
|
|
4
|
+
return trimmed && trimmed.length > 0 ? trimmed : undefined;
|
|
5
|
+
}
|
|
6
|
+
export function buildCompatibilityWorkspaceScope(options) {
|
|
7
|
+
return {
|
|
8
|
+
provider: options.provider,
|
|
9
|
+
source: "compatibility",
|
|
10
|
+
compatibilityKey: normalizeScopeValue(options.compatibilityKey) ?? DEFAULT_COMPATIBILITY_SCOPE_KEY,
|
|
11
|
+
...(normalizeScopeValue(options.workspaceId)
|
|
12
|
+
? { workspaceId: normalizeScopeValue(options.workspaceId) }
|
|
13
|
+
: {}),
|
|
14
|
+
...(normalizeScopeValue(options.installId)
|
|
15
|
+
? { installId: normalizeScopeValue(options.installId) }
|
|
16
|
+
: {}),
|
|
17
|
+
...(normalizeScopeValue(options.channelId)
|
|
18
|
+
? { channelId: normalizeScopeValue(options.channelId) }
|
|
19
|
+
: {}),
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
export function buildCompatibilityInstanceScope(options = {}) {
|
|
23
|
+
return {
|
|
24
|
+
source: "compatibility",
|
|
25
|
+
compatibilityKey: normalizeScopeValue(options.compatibilityKey) ?? DEFAULT_COMPATIBILITY_SCOPE_KEY,
|
|
26
|
+
...(normalizeScopeValue(options.instanceId)
|
|
27
|
+
? { instanceId: normalizeScopeValue(options.instanceId) }
|
|
28
|
+
: {}),
|
|
29
|
+
...(normalizeScopeValue(options.instanceName)
|
|
30
|
+
? { instanceName: normalizeScopeValue(options.instanceName) }
|
|
31
|
+
: {}),
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
export function buildRuntimeScopeCarrier(options) {
|
|
35
|
+
const scope = {};
|
|
36
|
+
if (options.workspace) {
|
|
37
|
+
scope.workspace = options.workspace;
|
|
38
|
+
}
|
|
39
|
+
if (options.instance) {
|
|
40
|
+
scope.instance = options.instance;
|
|
41
|
+
}
|
|
42
|
+
return Object.keys(scope).length > 0 ? scope : undefined;
|
|
43
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pinet/transport-core",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Transport-neutral message contracts for pi transports",
|
|
6
|
+
"author": "Will Porcellini <5994936+gugu91@users.noreply.github.com>",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/gugu91/extensions.git",
|
|
11
|
+
"directory": "transport-core"
|
|
12
|
+
},
|
|
13
|
+
"publishConfig": {
|
|
14
|
+
"access": "public"
|
|
15
|
+
},
|
|
16
|
+
"main": "./dist/index.js",
|
|
17
|
+
"exports": {
|
|
18
|
+
".": "./dist/index.js",
|
|
19
|
+
"./package.json": "./package.json"
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"README.md",
|
|
23
|
+
"LICENSE",
|
|
24
|
+
"dist/"
|
|
25
|
+
],
|
|
26
|
+
"pi": {},
|
|
27
|
+
"scripts": {
|
|
28
|
+
"build": "node ../scripts/build-package.mjs",
|
|
29
|
+
"prepack": "pnpm run build",
|
|
30
|
+
"lint": "eslint . --ext .ts",
|
|
31
|
+
"typecheck": "tsc --noEmit",
|
|
32
|
+
"test": "node --experimental-strip-types --test *.test.ts"
|
|
33
|
+
},
|
|
34
|
+
"types": "./dist/index.d.ts"
|
|
35
|
+
}
|