@temps-sdk/plugin 0.1.0-beta.1 → 0.1.0-beta.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/ai.d.ts +32 -0
- package/dist/ai.d.ts.map +1 -0
- package/dist/ai.js +38 -0
- package/dist/ai.js.map +1 -0
- package/dist/client.d.ts +41 -10
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +146 -89
- package/dist/client.js.map +1 -1
- package/dist/context.d.ts +21 -12
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +25 -36
- package/dist/context.js.map +1 -1
- package/dist/errors.d.ts +0 -23
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +0 -46
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +36 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +42 -6
- package/dist/index.js.map +1 -1
- package/dist/launch.d.ts +9 -0
- package/dist/launch.d.ts.map +1 -0
- package/dist/launch.js +96 -0
- package/dist/launch.js.map +1 -0
- package/dist/manifest-builder.d.ts +4 -9
- package/dist/manifest-builder.d.ts.map +1 -1
- package/dist/manifest-builder.js +7 -26
- package/dist/manifest-builder.js.map +1 -1
- package/dist/protocol.d.ts +28 -14
- package/dist/protocol.d.ts.map +1 -1
- package/dist/protocol.js +49 -94
- package/dist/protocol.js.map +1 -1
- package/dist/runtime.d.ts +21 -12
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +318 -426
- package/dist/runtime.js.map +1 -1
- package/dist/types.d.ts +147 -151
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +1 -4
- package/dist/types.js.map +1 -1
- package/dist/ui.d.ts.map +1 -1
- package/dist/ui.js +7 -26
- package/dist/ui.js.map +1 -1
- package/package.json +10 -19
- package/LICENSE +0 -21
- package/README.md +0 -123
- package/dist/api.d.ts +0 -33
- package/dist/api.d.ts.map +0 -1
- package/dist/api.js +0 -96
- package/dist/api.js.map +0 -1
- package/dist/auth.d.ts +0 -41
- package/dist/auth.d.ts.map +0 -1
- package/dist/auth.js +0 -102
- package/dist/auth.js.map +0 -1
package/dist/ai.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { TempsClient } from "./client.js";
|
|
2
|
+
import type { PluginAiRequest, PluginAiResponse, PluginHostCapabilities } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Host-mediated AI. No provider key, user token, or claimed actor identity is needed.
|
|
5
|
+
* Declare `.requestPermissions("ai_generate")` in the manifest and ask an
|
|
6
|
+
* administrator to approve it in Settings → Plugins → Permissions.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* const access = await ctx.permissions();
|
|
11
|
+
* if (access.ai.configured && access.permissions.includes("ai_generate")) {
|
|
12
|
+
* const result = await ctx.ai.generate({
|
|
13
|
+
* purpose: "page-audit",
|
|
14
|
+
* prompt: "Suggest a clearer title for this public page: ...",
|
|
15
|
+
* max_tokens: 512,
|
|
16
|
+
* });
|
|
17
|
+
* // Treat result.text as untrusted output; review before applying changes.
|
|
18
|
+
* }
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export declare class PluginAiClient {
|
|
22
|
+
private readonly client;
|
|
23
|
+
constructor(client: TempsClient);
|
|
24
|
+
/** Includes live grants and setup information, including when AI is not configured. */
|
|
25
|
+
capabilities(): Promise<PluginHostCapabilities>;
|
|
26
|
+
/**
|
|
27
|
+
* The host enforces permission and usage limits, including for background jobs.
|
|
28
|
+
* A grant may be revoked after capabilities() returns; handle permission_denied.
|
|
29
|
+
*/
|
|
30
|
+
generate(input: PluginAiRequest): Promise<PluginAiResponse>;
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=ai.d.ts.map
|
package/dist/ai.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ai.d.ts","sourceRoot":"","sources":["../src/ai.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,KAAK,EACV,eAAe,EACf,gBAAgB,EAChB,sBAAsB,EACvB,MAAM,YAAY,CAAC;AAEpB;;;;;;;;;;;;;;;;;GAiBG;AACH,qBAAa,cAAc;IACb,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAN,MAAM,EAAE,WAAW;IAEhD,uFAAuF;IACvF,YAAY,IAAI,OAAO,CAAC,sBAAsB,CAAC;IAI/C;;;OAGG;IACH,QAAQ,CAAC,KAAK,EAAE,eAAe,GAAG,OAAO,CAAC,gBAAgB,CAAC;CAG5D"}
|
package/dist/ai.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2024-2026 Temps Contributors
|
|
2
|
+
// SPDX-License-Identifier: MIT OR Apache-2.0
|
|
3
|
+
/**
|
|
4
|
+
* Host-mediated AI. No provider key, user token, or claimed actor identity is needed.
|
|
5
|
+
* Declare `.requestPermissions("ai_generate")` in the manifest and ask an
|
|
6
|
+
* administrator to approve it in Settings → Plugins → Permissions.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* const access = await ctx.permissions();
|
|
11
|
+
* if (access.ai.configured && access.permissions.includes("ai_generate")) {
|
|
12
|
+
* const result = await ctx.ai.generate({
|
|
13
|
+
* purpose: "page-audit",
|
|
14
|
+
* prompt: "Suggest a clearer title for this public page: ...",
|
|
15
|
+
* max_tokens: 512,
|
|
16
|
+
* });
|
|
17
|
+
* // Treat result.text as untrusted output; review before applying changes.
|
|
18
|
+
* }
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export class PluginAiClient {
|
|
22
|
+
client;
|
|
23
|
+
constructor(client) {
|
|
24
|
+
this.client = client;
|
|
25
|
+
}
|
|
26
|
+
/** Includes live grants and setup information, including when AI is not configured. */
|
|
27
|
+
capabilities() {
|
|
28
|
+
return this.client.getHostCapabilities();
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* The host enforces permission and usage limits, including for background jobs.
|
|
32
|
+
* A grant may be revoked after capabilities() returns; handle permission_denied.
|
|
33
|
+
*/
|
|
34
|
+
generate(input) {
|
|
35
|
+
return this.client.generateAi(input);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=ai.js.map
|
package/dist/ai.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ai.js","sourceRoot":"","sources":["../src/ai.ts"],"names":[],"mappings":"AAAA,uDAAuD;AACvD,6CAA6C;AAS7C;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,OAAO,cAAc;IACI;IAA7B,YAA6B,MAAmB;QAAnB,WAAM,GAAN,MAAM,CAAa;IAAG,CAAC;IAEpD,uFAAuF;IACvF,YAAY;QACV,OAAO,IAAI,CAAC,MAAM,CAAC,mBAAmB,EAAE,CAAC;IAC3C,CAAC;IAED;;;OAGG;IACH,QAAQ,CAAC,KAAsB;QAC7B,OAAO,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;IACvC,CAAC;CACF"}
|
package/dist/client.d.ts
CHANGED
|
@@ -1,19 +1,39 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* TempsClient -- typed async client for querying platform data over
|
|
3
|
+
* the WebSocket data channel.
|
|
4
|
+
*
|
|
5
|
+
* Mirrors: crates/temps-plugin-sdk/src/client.rs
|
|
6
|
+
*
|
|
7
|
+
* The client maintains a monotonically increasing request ID and a map
|
|
8
|
+
* of pending requests. Each request sends a `ChannelRequest` frame over
|
|
9
|
+
* the WebSocket and waits for a matching `ChannelResponse` by ID.
|
|
10
|
+
*/
|
|
11
|
+
import type { ProjectInfo, EnvironmentInfo, DeploymentInfo, PluginEvent, PluginHostCapabilities, PluginAiRequest, PluginAiResponse } from "./types.js";
|
|
12
|
+
/**
|
|
13
|
+
* Minimal WebSocket-like interface accepted by TempsClient.
|
|
14
|
+
* Compatible with both the `ws` package and the Bun WebSocket adapter.
|
|
15
|
+
*/
|
|
2
16
|
export interface WsLike {
|
|
3
|
-
on(event:
|
|
4
|
-
|
|
5
|
-
on(event: "error", fn: (error: unknown) => void): void;
|
|
6
|
-
send(data: string, callback?: (error?: Error) => void): void;
|
|
17
|
+
on(event: string, fn: (...args: unknown[]) => void): void;
|
|
18
|
+
send(data: string, cb?: (err?: Error) => void): void;
|
|
7
19
|
close(): void;
|
|
8
20
|
}
|
|
9
21
|
export declare class TempsClient {
|
|
10
|
-
|
|
22
|
+
private ws;
|
|
23
|
+
private nextId;
|
|
24
|
+
private pending;
|
|
25
|
+
private closed;
|
|
26
|
+
private eventHandler?;
|
|
27
|
+
private timeoutMs;
|
|
11
28
|
constructor(ws: WsLike, options?: {
|
|
12
29
|
timeoutMs?: number;
|
|
13
30
|
});
|
|
14
|
-
|
|
31
|
+
/**
|
|
32
|
+
* Register a handler for platform events pushed over the channel.
|
|
33
|
+
*/
|
|
34
|
+
onEvent(handler: (event: PluginEvent) => void): void;
|
|
15
35
|
getProject(projectId: number): Promise<ProjectInfo>;
|
|
16
|
-
listProjects(): Promise<ProjectInfo[]>;
|
|
36
|
+
listProjects(limit?: number): Promise<ProjectInfo[]>;
|
|
17
37
|
getEnvironment(environmentId: number): Promise<EnvironmentInfo>;
|
|
18
38
|
listEnvironments(projectId: number): Promise<EnvironmentInfo[]>;
|
|
19
39
|
getDeployment(deploymentId: number): Promise<DeploymentInfo>;
|
|
@@ -22,8 +42,19 @@ export declare class TempsClient {
|
|
|
22
42
|
environmentId?: number;
|
|
23
43
|
limit?: number;
|
|
24
44
|
}): Promise<DeploymentInfo[]>;
|
|
25
|
-
|
|
26
|
-
|
|
45
|
+
/**
|
|
46
|
+
* Send a typed channel request and wait for the response.
|
|
47
|
+
*/
|
|
48
|
+
private request;
|
|
49
|
+
private handleMessage;
|
|
50
|
+
private handleResponse;
|
|
51
|
+
/**
|
|
52
|
+
* Close the WebSocket connection.
|
|
53
|
+
*/
|
|
27
54
|
close(): void;
|
|
55
|
+
/** Read live host grants. Do not cache this as an authorization decision. */
|
|
56
|
+
getHostCapabilities(): Promise<PluginHostCapabilities>;
|
|
57
|
+
/** Generate through the host's configured AI provider, without exposing its credentials. */
|
|
58
|
+
generateAi(input: PluginAiRequest): Promise<PluginAiResponse>;
|
|
28
59
|
}
|
|
29
60
|
//# sourceMappingURL=client.d.ts.map
|
package/dist/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAGA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAIV,WAAW,EACX,eAAe,EACf,cAAc,EACd,WAAW,EACX,sBAAsB,EACtB,eAAe,EACf,gBAAgB,EACjB,MAAM,YAAY,CAAC;AASpB;;;GAGG;AACH,MAAM,WAAW,MAAM;IACrB,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,GAAG,IAAI,CAAC;IAC1D,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,KAAK,KAAK,IAAI,GAAG,IAAI,CAAC;IACrD,KAAK,IAAI,IAAI,CAAC;CACf;AASD,qBAAa,WAAW;IACtB,OAAO,CAAC,EAAE,CAAS;IACnB,OAAO,CAAC,MAAM,CAAK;IACnB,OAAO,CAAC,OAAO,CAAqC;IACpD,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,YAAY,CAAC,CAA+B;IACpD,OAAO,CAAC,SAAS,CAAS;gBAEd,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE;IAwBxD;;OAEG;IACH,OAAO,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,IAAI,GAAG,IAAI;IAQ9C,UAAU,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;IAInD,YAAY,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;IAIpD,cAAc,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC;IAM/D,gBAAgB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,EAAE,CAAC;IAM/D,aAAa,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;IAM5D,iBAAiB,CACrB,SAAS,EAAE,MAAM,EACjB,aAAa,CAAC,EAAE,MAAM,GACrB,OAAO,CAAC,cAAc,CAAC;IAOpB,eAAe,CACnB,SAAS,EAAE,MAAM,EACjB,OAAO,CAAC,EAAE;QAAE,aAAa,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,GACnD,OAAO,CAAC,cAAc,EAAE,CAAC;IAY5B;;OAEG;IACH,OAAO,CAAC,OAAO;IAsDf,OAAO,CAAC,aAAa;IA4BrB,OAAO,CAAC,cAAc;IA+BtB;;OAEG;IACH,KAAK,IAAI,IAAI;IASb,6EAA6E;IACvE,mBAAmB,IAAI,OAAO,CAAC,sBAAsB,CAAC;IAI5D,4FAA4F;IACtF,UAAU,CAAC,KAAK,EAAE,eAAe,GAAG,OAAO,CAAC,gBAAgB,CAAC;CAcpE"}
|
package/dist/client.js
CHANGED
|
@@ -1,141 +1,198 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: 2024-2026 Temps Contributors
|
|
2
2
|
// SPDX-License-Identifier: MIT OR Apache-2.0
|
|
3
|
-
import { ChannelClosedError, ChannelTimeoutError, PlatformError,
|
|
3
|
+
import { ChannelClosedError, ChannelTimeoutError, PlatformError, } from "./errors.js";
|
|
4
4
|
const DEFAULT_TIMEOUT_MS = 10_000;
|
|
5
5
|
export class TempsClient {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
ws;
|
|
7
|
+
nextId = 1;
|
|
8
|
+
pending = new Map();
|
|
9
|
+
closed = false;
|
|
10
|
+
eventHandler;
|
|
11
|
+
timeoutMs;
|
|
12
12
|
constructor(ws, options) {
|
|
13
|
-
this
|
|
14
|
-
this
|
|
15
|
-
ws.on("message", (data) =>
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
13
|
+
this.ws = ws;
|
|
14
|
+
this.timeoutMs = options?.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
15
|
+
this.ws.on("message", (data) => {
|
|
16
|
+
this.handleMessage(data);
|
|
17
|
+
});
|
|
18
|
+
this.ws.on("close", () => {
|
|
19
|
+
this.closed = true;
|
|
20
|
+
// Reject all pending requests
|
|
21
|
+
for (const [id, pending] of this.pending) {
|
|
22
|
+
clearTimeout(pending.timer);
|
|
23
|
+
pending.reject(new ChannelClosedError());
|
|
24
|
+
this.pending.delete(id);
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
this.ws.on("error", (err) => {
|
|
28
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
29
|
+
console.error("[temps-plugin] WebSocket error:", msg);
|
|
19
30
|
});
|
|
20
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* Register a handler for platform events pushed over the channel.
|
|
34
|
+
*/
|
|
21
35
|
onEvent(handler) {
|
|
22
|
-
this
|
|
36
|
+
this.eventHandler = handler;
|
|
23
37
|
}
|
|
24
|
-
|
|
25
|
-
|
|
38
|
+
// -------------------------------------------------------------------------
|
|
39
|
+
// Platform Data Queries
|
|
40
|
+
// -------------------------------------------------------------------------
|
|
41
|
+
async getProject(projectId) {
|
|
42
|
+
return this.request("get_project", { project_id: projectId });
|
|
26
43
|
}
|
|
27
|
-
listProjects() {
|
|
28
|
-
return this.
|
|
44
|
+
async listProjects(limit) {
|
|
45
|
+
return this.request("list_projects", { limit });
|
|
29
46
|
}
|
|
30
|
-
getEnvironment(environmentId) {
|
|
31
|
-
return this.
|
|
47
|
+
async getEnvironment(environmentId) {
|
|
48
|
+
return this.request("get_environment", {
|
|
49
|
+
environment_id: environmentId,
|
|
50
|
+
});
|
|
32
51
|
}
|
|
33
|
-
listEnvironments(projectId) {
|
|
34
|
-
return this.
|
|
52
|
+
async listEnvironments(projectId) {
|
|
53
|
+
return this.request("list_environments", {
|
|
54
|
+
project_id: projectId,
|
|
55
|
+
});
|
|
35
56
|
}
|
|
36
|
-
getDeployment(deploymentId) {
|
|
37
|
-
return this.
|
|
57
|
+
async getDeployment(deploymentId) {
|
|
58
|
+
return this.request("get_deployment", {
|
|
59
|
+
deployment_id: deploymentId,
|
|
60
|
+
});
|
|
38
61
|
}
|
|
39
|
-
getLastDeployment(projectId, environmentId) {
|
|
40
|
-
return this.
|
|
62
|
+
async getLastDeployment(projectId, environmentId) {
|
|
63
|
+
return this.request("get_last_deployment", {
|
|
41
64
|
project_id: projectId,
|
|
42
65
|
environment_id: environmentId,
|
|
43
|
-
})
|
|
66
|
+
});
|
|
44
67
|
}
|
|
45
|
-
listDeployments(projectId, options) {
|
|
46
|
-
return this.
|
|
68
|
+
async listDeployments(projectId, options) {
|
|
69
|
+
return this.request("list_deployments", {
|
|
47
70
|
project_id: projectId,
|
|
48
71
|
environment_id: options?.environmentId,
|
|
49
72
|
limit: options?.limit,
|
|
50
|
-
})
|
|
51
|
-
}
|
|
52
|
-
apiCall(call) {
|
|
53
|
-
return this.call("api_call", call);
|
|
73
|
+
});
|
|
54
74
|
}
|
|
55
|
-
|
|
56
|
-
|
|
75
|
+
// -------------------------------------------------------------------------
|
|
76
|
+
// Low-level request/response
|
|
77
|
+
// -------------------------------------------------------------------------
|
|
78
|
+
/**
|
|
79
|
+
* Send a typed channel request and wait for the response.
|
|
80
|
+
*/
|
|
81
|
+
request(method, params, timeoutMs = this.timeoutMs) {
|
|
82
|
+
if (this.closed) {
|
|
57
83
|
return Promise.reject(new ChannelClosedError());
|
|
58
|
-
|
|
59
|
-
const
|
|
84
|
+
}
|
|
85
|
+
const id = this.nextId++;
|
|
86
|
+
// Filter out undefined values from params
|
|
87
|
+
const cleanParams = {};
|
|
88
|
+
for (const [key, value] of Object.entries(params)) {
|
|
89
|
+
if (value !== undefined) {
|
|
90
|
+
cleanParams[key] = value;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
const msg = {
|
|
60
94
|
type: "request",
|
|
61
95
|
id,
|
|
62
|
-
call: { method, params },
|
|
96
|
+
call: { method, params: cleanParams },
|
|
63
97
|
};
|
|
64
98
|
return new Promise((resolve, reject) => {
|
|
65
99
|
const timer = setTimeout(() => {
|
|
66
|
-
this
|
|
67
|
-
reject(new ChannelTimeoutError(method,
|
|
68
|
-
},
|
|
69
|
-
this
|
|
100
|
+
this.pending.delete(id);
|
|
101
|
+
reject(new ChannelTimeoutError(method, timeoutMs));
|
|
102
|
+
}, timeoutMs);
|
|
103
|
+
this.pending.set(id, {
|
|
70
104
|
method,
|
|
71
|
-
resolve:
|
|
105
|
+
resolve: resolve,
|
|
72
106
|
reject,
|
|
73
107
|
timer,
|
|
74
108
|
});
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
109
|
+
try {
|
|
110
|
+
this.ws.send(JSON.stringify(msg), (err) => {
|
|
111
|
+
if (err) {
|
|
112
|
+
clearTimeout(timer);
|
|
113
|
+
this.pending.delete(id);
|
|
114
|
+
reject(err);
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
catch (error) {
|
|
78
119
|
clearTimeout(timer);
|
|
79
|
-
this
|
|
120
|
+
this.pending.delete(id);
|
|
80
121
|
reject(error);
|
|
81
|
-
}
|
|
122
|
+
}
|
|
82
123
|
});
|
|
83
124
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
this.#ws.close();
|
|
87
|
-
this.#closePending();
|
|
88
|
-
}
|
|
89
|
-
#handleMessage(data) {
|
|
90
|
-
let message;
|
|
125
|
+
handleMessage(data) {
|
|
126
|
+
let msg;
|
|
91
127
|
try {
|
|
92
|
-
|
|
128
|
+
const str = typeof data === "string" ? data : String(data);
|
|
129
|
+
msg = JSON.parse(str);
|
|
93
130
|
}
|
|
94
131
|
catch {
|
|
132
|
+
console.error("[temps-plugin] Failed to parse channel message");
|
|
95
133
|
return;
|
|
96
134
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
135
|
+
switch (msg.type) {
|
|
136
|
+
case "response":
|
|
137
|
+
this.handleResponse(msg);
|
|
138
|
+
break;
|
|
139
|
+
case "event":
|
|
140
|
+
if (this.eventHandler) {
|
|
141
|
+
this.eventHandler(msg.event);
|
|
142
|
+
}
|
|
143
|
+
break;
|
|
144
|
+
case "request":
|
|
145
|
+
// Plugins don't handle inbound requests from the host (yet)
|
|
146
|
+
console.warn(`[temps-plugin] Received unexpected request: ${msg.call.method}`);
|
|
147
|
+
break;
|
|
103
148
|
}
|
|
104
149
|
}
|
|
105
|
-
|
|
106
|
-
const pending = this
|
|
107
|
-
if (!pending)
|
|
150
|
+
handleResponse(msg) {
|
|
151
|
+
const pending = this.pending.get(msg.id);
|
|
152
|
+
if (!pending) {
|
|
153
|
+
console.warn(`[temps-plugin] Received response for unknown request ID: ${msg.id}`);
|
|
108
154
|
return;
|
|
155
|
+
}
|
|
109
156
|
clearTimeout(pending.timer);
|
|
110
|
-
this
|
|
111
|
-
if ("err" in
|
|
112
|
-
pending.reject(new PlatformError(
|
|
113
|
-
return;
|
|
157
|
+
this.pending.delete(msg.id);
|
|
158
|
+
if (msg.outcome && "err" in msg.outcome) {
|
|
159
|
+
pending.reject(new PlatformError(msg.outcome.err.code, msg.outcome.err.message));
|
|
114
160
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
161
|
+
else if (msg.outcome &&
|
|
162
|
+
"ok" in msg.outcome &&
|
|
163
|
+
msg.outcome.ok.method === pending.method) {
|
|
164
|
+
pending.resolve(msg.outcome.ok.result);
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
pending.reject(new Error(`Platform channel response does not match ${pending.method}; rebuild the plugin against this Temps version`));
|
|
119
168
|
}
|
|
120
|
-
pending.resolve(response.result);
|
|
121
169
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
170
|
+
/**
|
|
171
|
+
* Close the WebSocket connection.
|
|
172
|
+
*/
|
|
173
|
+
close() {
|
|
174
|
+
this.closed = true;
|
|
175
|
+
for (const pending of this.pending.values()) {
|
|
125
176
|
clearTimeout(pending.timer);
|
|
126
|
-
pending.reject(
|
|
177
|
+
pending.reject(new ChannelClosedError());
|
|
127
178
|
}
|
|
128
|
-
this
|
|
179
|
+
this.pending.clear();
|
|
180
|
+
this.ws.close();
|
|
181
|
+
}
|
|
182
|
+
/** Read live host grants. Do not cache this as an authorization decision. */
|
|
183
|
+
async getHostCapabilities() {
|
|
184
|
+
return this.request("get_host_capabilities", {});
|
|
185
|
+
}
|
|
186
|
+
/** Generate through the host's configured AI provider, without exposing its credentials. */
|
|
187
|
+
async generateAi(input) {
|
|
188
|
+
// Explicit fields prevent accidental forwarding of credentials or actor identifiers.
|
|
189
|
+
return this.request("generate_ai", {
|
|
190
|
+
purpose: input.purpose,
|
|
191
|
+
prompt: input.prompt,
|
|
192
|
+
system: input.system,
|
|
193
|
+
max_tokens: input.max_tokens,
|
|
194
|
+
temperature: input.temperature,
|
|
195
|
+
}, 65_000);
|
|
129
196
|
}
|
|
130
|
-
}
|
|
131
|
-
function normalizeMessage(data) {
|
|
132
|
-
if (typeof data === "string")
|
|
133
|
-
return data;
|
|
134
|
-
if (data instanceof Uint8Array)
|
|
135
|
-
return Buffer.from(data).toString("utf8");
|
|
136
|
-
return String(data);
|
|
137
|
-
}
|
|
138
|
-
function compact(value) {
|
|
139
|
-
return Object.fromEntries(Object.entries(value).filter(([, entry]) => entry !== undefined));
|
|
140
197
|
}
|
|
141
198
|
//# sourceMappingURL=client.js.map
|
package/dist/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,uDAAuD;AACvD,6CAA6C;
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,uDAAuD;AACvD,6CAA6C;AAyB7C,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACnB,aAAa,GACd,MAAM,aAAa,CAAC;AAErB,MAAM,kBAAkB,GAAG,MAAM,CAAC;AAmBlC,MAAM,OAAO,WAAW;IACd,EAAE,CAAS;IACX,MAAM,GAAG,CAAC,CAAC;IACX,OAAO,GAAG,IAAI,GAAG,EAA0B,CAAC;IAC5C,MAAM,GAAG,KAAK,CAAC;IACf,YAAY,CAAgC;IAC5C,SAAS,CAAS;IAE1B,YAAY,EAAU,EAAE,OAAgC;QACtD,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;QACb,IAAI,CAAC,SAAS,GAAG,OAAO,EAAE,SAAS,IAAI,kBAAkB,CAAC;QAE1D,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC,SAAS,EAAE,CAAC,IAAa,EAAE,EAAE;YACtC,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;QAC3B,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE;YACvB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;YACnB,8BAA8B;YAC9B,KAAK,MAAM,CAAC,EAAE,EAAE,OAAO,CAAC,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;gBACzC,YAAY,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;g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mirrors: crates/temps-plugin-sdk/src/context.rs
|
|
5
|
+
*/
|
|
3
6
|
import type { TempsClient } from "./client.js";
|
|
7
|
+
import { PluginAiClient } from "./ai.js";
|
|
8
|
+
import type { PluginHostCapabilities } from "./types.js";
|
|
4
9
|
export declare class PluginContext {
|
|
5
|
-
|
|
10
|
+
private readonly _pluginName;
|
|
11
|
+
private readonly _dataDir;
|
|
12
|
+
private readonly _authSecret;
|
|
13
|
+
private readonly _client;
|
|
14
|
+
readonly ai: PluginAiClient;
|
|
6
15
|
constructor(options: {
|
|
7
16
|
pluginName: string;
|
|
8
17
|
dataDir: string;
|
|
9
|
-
databaseUrl?: string;
|
|
10
|
-
hostDataDir?: string;
|
|
11
|
-
hostApiUrl?: string;
|
|
12
18
|
authSecret: string;
|
|
13
19
|
client: TempsClient;
|
|
14
20
|
});
|
|
21
|
+
/** The platform data client for querying projects, deployments, etc. */
|
|
15
22
|
get temps(): TempsClient;
|
|
16
|
-
|
|
23
|
+
/** Fetch current actor, effective permissions, and AI setup/limits from the host. */
|
|
24
|
+
permissions(): Promise<PluginHostCapabilities>;
|
|
25
|
+
/** The plugin's unique name (kebab-case). */
|
|
17
26
|
get pluginName(): string;
|
|
27
|
+
/**
|
|
28
|
+
* Persistent data directory for this plugin.
|
|
29
|
+
* Use this for SQLite databases, config files, caches, etc.
|
|
30
|
+
*/
|
|
18
31
|
get dataDir(): string;
|
|
19
|
-
|
|
20
|
-
get hostDataDir(): string | undefined;
|
|
21
|
-
get hostApiUrl(): string | undefined;
|
|
22
|
-
get mountUrl(): string | undefined;
|
|
23
|
-
/** Per-process assertion secret. Prefer extractAuthContext over manual use. */
|
|
32
|
+
/** HMAC secret for validating request authenticity. */
|
|
24
33
|
get authSecret(): string;
|
|
25
34
|
}
|
|
26
35
|
//# sourceMappingURL=context.d.ts.map
|
package/dist/context.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAEzD,qBAAa,aAAa;IACxB,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAS;IACrC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;IAClC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAS;IACrC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAc;IACtC,QAAQ,CAAC,EAAE,EAAE,cAAc,CAAC;gBAEhB,OAAO,EAAE;QACnB,UAAU,EAAE,MAAM,CAAC;QACnB,OAAO,EAAE,MAAM,CAAC;QAChB,UAAU,EAAE,MAAM,CAAC;QACnB,MAAM,EAAE,WAAW,CAAC;KACrB;IAQD,wEAAwE;IACxE,IAAI,KAAK,IAAI,WAAW,CAEvB;IAED,qFAAqF;IACrF,WAAW,IAAI,OAAO,CAAC,sBAAsB,CAAC;IAI9C,6CAA6C;IAC7C,IAAI,UAAU,IAAI,MAAM,CAEvB;IAED;;;OAGG;IACH,IAAI,OAAO,IAAI,MAAM,CAEpB;IAED,uDAAuD;IACvD,IAAI,UAAU,IAAI,MAAM,CAEvB;CACF"}
|
package/dist/context.js
CHANGED
|
@@ -1,52 +1,41 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: 2024-2026 Temps Contributors
|
|
2
2
|
// SPDX-License-Identifier: MIT OR Apache-2.0
|
|
3
|
-
import {
|
|
3
|
+
import { PluginAiClient } from "./ai.js";
|
|
4
4
|
export class PluginContext {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
#authSecret;
|
|
11
|
-
#client;
|
|
5
|
+
_pluginName;
|
|
6
|
+
_dataDir;
|
|
7
|
+
_authSecret;
|
|
8
|
+
_client;
|
|
9
|
+
ai;
|
|
12
10
|
constructor(options) {
|
|
13
|
-
this
|
|
14
|
-
this
|
|
15
|
-
this
|
|
16
|
-
this
|
|
17
|
-
this
|
|
18
|
-
this.#authSecret = options.authSecret;
|
|
19
|
-
this.#client = options.client;
|
|
11
|
+
this._pluginName = options.pluginName;
|
|
12
|
+
this._dataDir = options.dataDir;
|
|
13
|
+
this._authSecret = options.authSecret;
|
|
14
|
+
this._client = options.client;
|
|
15
|
+
this.ai = new PluginAiClient(options.client);
|
|
20
16
|
}
|
|
17
|
+
/** The platform data client for querying projects, deployments, etc. */
|
|
21
18
|
get temps() {
|
|
22
|
-
return this
|
|
19
|
+
return this._client;
|
|
23
20
|
}
|
|
24
|
-
|
|
25
|
-
|
|
21
|
+
/** Fetch current actor, effective permissions, and AI setup/limits from the host. */
|
|
22
|
+
permissions() {
|
|
23
|
+
return this._client.getHostCapabilities();
|
|
26
24
|
}
|
|
25
|
+
/** The plugin's unique name (kebab-case). */
|
|
27
26
|
get pluginName() {
|
|
28
|
-
return this
|
|
27
|
+
return this._pluginName;
|
|
29
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* Persistent data directory for this plugin.
|
|
31
|
+
* Use this for SQLite databases, config files, caches, etc.
|
|
32
|
+
*/
|
|
30
33
|
get dataDir() {
|
|
31
|
-
return this
|
|
34
|
+
return this._dataDir;
|
|
32
35
|
}
|
|
33
|
-
|
|
34
|
-
return this.#databaseUrl;
|
|
35
|
-
}
|
|
36
|
-
get hostDataDir() {
|
|
37
|
-
return this.#hostDataDir;
|
|
38
|
-
}
|
|
39
|
-
get hostApiUrl() {
|
|
40
|
-
return this.#hostApiUrl;
|
|
41
|
-
}
|
|
42
|
-
get mountUrl() {
|
|
43
|
-
return this.#hostApiUrl === undefined
|
|
44
|
-
? undefined
|
|
45
|
-
: `${this.#hostApiUrl.replace(/\/$/, "")}/api/x/${this.#pluginName}`;
|
|
46
|
-
}
|
|
47
|
-
/** Per-process assertion secret. Prefer extractAuthContext over manual use. */
|
|
36
|
+
/** HMAC secret for validating request authenticity. */
|
|
48
37
|
get authSecret() {
|
|
49
|
-
return this
|
|
38
|
+
return this._authSecret;
|
|
50
39
|
}
|
|
51
40
|
}
|
|
52
41
|
//# sourceMappingURL=context.js.map
|
package/dist/context.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.js","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAAA,uDAAuD;AACvD,6CAA6C;
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAAA,uDAAuD;AACvD,6CAA6C;AAS7C,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAGzC,MAAM,OAAO,aAAa;IACP,WAAW,CAAS;IACpB,QAAQ,CAAS;IACjB,WAAW,CAAS;IACpB,OAAO,CAAc;IAC7B,EAAE,CAAiB;IAE5B,YAAY,OAKX;QACC,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC;QACtC,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,OAAO,CAAC;QAChC,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC;QACtC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC;QAC9B,IAAI,CAAC,EAAE,GAAG,IAAI,cAAc,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IAC/C,CAAC;IAED,wEAAwE;IACxE,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED,qFAAqF;IACrF,WAAW;QACT,OAAO,IAAI,CAAC,OAAO,CAAC,mBAAmB,EAAE,CAAC;IAC5C,CAAC;IAED,6CAA6C;IAC7C,IAAI,UAAU;QACZ,OAAO,IAAI,CAAC,WAAW,CAAC;IAC1B,CAAC;IAED;;;OAGG;IACH,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAED,uDAAuD;IACvD,IAAI,UAAU;QACZ,OAAO,IAAI,CAAC,WAAW,CAAC;IAC1B,CAAC;CACF"}
|