every-plugin 0.1.1 → 0.1.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/errors.d.ts +9 -5
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +3 -14
- package/dist/plugin.d.ts +73 -13
- package/dist/plugin.d.ts.map +1 -1
- package/dist/plugin.js +55 -4
- package/dist/runtime/errors.d.ts +6 -1
- package/dist/runtime/errors.d.ts.map +1 -1
- package/dist/runtime/errors.js +40 -0
- package/dist/runtime/index.d.ts +2 -2
- package/dist/runtime/index.d.ts.map +1 -1
- package/dist/runtime/services/module-federation.service.d.ts.map +1 -1
- package/dist/runtime/services/module-federation.service.js +16 -24
- package/dist/runtime/services/plugin.service.d.ts +2 -2
- package/dist/runtime/services/plugin.service.d.ts.map +1 -1
- package/dist/runtime/services/plugin.service.js +4 -2
- package/dist/runtime/streaming/streaming.d.ts +3 -3
- package/dist/runtime/streaming/streaming.d.ts.map +1 -1
- package/dist/runtime/streaming/streaming.js +8 -2
- package/dist/runtime/streaming/types.d.ts +1 -1
- package/dist/runtime/streaming/types.d.ts.map +1 -1
- package/package.json +10 -14
package/dist/errors.d.ts
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
declare const PluginConfigurationError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => import("effect/Cause").YieldableError & {
|
|
2
|
+
readonly _tag: "PluginConfigurationError";
|
|
3
|
+
} & Readonly<A>;
|
|
4
|
+
export declare class PluginConfigurationError extends PluginConfigurationError_base<{
|
|
5
|
+
readonly message: string;
|
|
2
6
|
readonly retryable: boolean;
|
|
3
|
-
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
constructor(message: string);
|
|
7
|
+
readonly cause?: Error;
|
|
8
|
+
}> {
|
|
9
|
+
get name(): string;
|
|
7
10
|
}
|
|
11
|
+
export {};
|
|
8
12
|
//# sourceMappingURL=errors.d.ts.map
|
package/dist/errors.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":";;;AAEA,qBAAa,wBAAyB,SAAQ,8BAA6C;IAC1F,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC;CACvB,CAAC;IACD,IAAa,IAAI,WAAyC;CAC1D"}
|
package/dist/errors.js
CHANGED
|
@@ -1,15 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
export class
|
|
3
|
-
|
|
4
|
-
constructor(message, retryable = true) {
|
|
5
|
-
super(message);
|
|
6
|
-
this.retryable = retryable;
|
|
7
|
-
this.name = "PluginExecutionError";
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
export class ConfigurationError extends PluginExecutionError {
|
|
11
|
-
constructor(message) {
|
|
12
|
-
super(message, false); // Configuration errors are not retryable
|
|
13
|
-
this.name = "ConfigurationError";
|
|
14
|
-
}
|
|
1
|
+
import { Data } from "effect";
|
|
2
|
+
export class PluginConfigurationError extends Data.TaggedError("PluginConfigurationError") {
|
|
3
|
+
get name() { return "PluginConfigurationError"; }
|
|
15
4
|
}
|
package/dist/plugin.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import type { ContractRouter, Meta } from "@orpc/server";
|
|
1
2
|
import { Context, Effect } from "effect";
|
|
2
3
|
import { z } from "zod";
|
|
3
|
-
import type {
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
import type { PluginConfigurationError } from "./errors";
|
|
5
|
+
export type Contract = ContractRouter<Meta>;
|
|
6
|
+
export declare function createConfigSchema<V extends z.ZodTypeAny, S extends z.ZodTypeAny>(variablesSchema: V, secretsSchema: S): z.ZodObject<{
|
|
7
|
+
variables: V;
|
|
8
|
+
secrets: S;
|
|
7
9
|
}, z.core.$strip>;
|
|
8
10
|
export declare function createStateSchema<T extends z.ZodTypeAny>(pluginStateSchema: T): z.ZodIntersection<z.ZodObject<{
|
|
9
11
|
nextPollMs: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
@@ -27,15 +29,73 @@ export interface PluginLogger {
|
|
|
27
29
|
declare const PluginLoggerTag_base: Context.TagClass<PluginLoggerTag, "PluginLogger", PluginLogger>;
|
|
28
30
|
export declare class PluginLoggerTag extends PluginLoggerTag_base {
|
|
29
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* Common error schemas that all plugins can use
|
|
34
|
+
* These provide consistent error handling across the plugin ecosystem
|
|
35
|
+
*/
|
|
36
|
+
export declare const CommonPluginErrors: {
|
|
37
|
+
UNAUTHORIZED: {
|
|
38
|
+
data: z.ZodObject<{
|
|
39
|
+
apiKeyProvided: z.ZodBoolean;
|
|
40
|
+
provider: z.ZodOptional<z.ZodString>;
|
|
41
|
+
authType: z.ZodOptional<z.ZodEnum<{
|
|
42
|
+
apiKey: "apiKey";
|
|
43
|
+
oauth: "oauth";
|
|
44
|
+
token: "token";
|
|
45
|
+
}>>;
|
|
46
|
+
}, z.core.$strip>;
|
|
47
|
+
};
|
|
48
|
+
RATE_LIMITED: {
|
|
49
|
+
data: z.ZodObject<{
|
|
50
|
+
retryAfter: z.ZodNumber;
|
|
51
|
+
remainingRequests: z.ZodOptional<z.ZodNumber>;
|
|
52
|
+
resetTime: z.ZodOptional<z.ZodString>;
|
|
53
|
+
limitType: z.ZodOptional<z.ZodEnum<{
|
|
54
|
+
requests: "requests";
|
|
55
|
+
tokens: "tokens";
|
|
56
|
+
bandwidth: "bandwidth";
|
|
57
|
+
}>>;
|
|
58
|
+
}, z.core.$strip>;
|
|
59
|
+
};
|
|
60
|
+
SERVICE_UNAVAILABLE: {
|
|
61
|
+
data: z.ZodObject<{
|
|
62
|
+
retryAfter: z.ZodOptional<z.ZodNumber>;
|
|
63
|
+
maintenanceWindow: z.ZodDefault<z.ZodBoolean>;
|
|
64
|
+
estimatedUptime: z.ZodOptional<z.ZodString>;
|
|
65
|
+
}, z.core.$strip>;
|
|
66
|
+
};
|
|
67
|
+
BAD_REQUEST: {
|
|
68
|
+
data: z.ZodObject<{
|
|
69
|
+
invalidFields: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
70
|
+
validationErrors: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
71
|
+
field: z.ZodString;
|
|
72
|
+
message: z.ZodString;
|
|
73
|
+
code: z.ZodOptional<z.ZodString>;
|
|
74
|
+
}, z.core.$strip>>>;
|
|
75
|
+
}, z.core.$strip>;
|
|
76
|
+
};
|
|
77
|
+
NOT_FOUND: {
|
|
78
|
+
data: z.ZodObject<{
|
|
79
|
+
resource: z.ZodOptional<z.ZodString>;
|
|
80
|
+
resourceId: z.ZodOptional<z.ZodString>;
|
|
81
|
+
}, z.core.$strip>;
|
|
82
|
+
};
|
|
83
|
+
FORBIDDEN: {
|
|
84
|
+
data: z.ZodObject<{
|
|
85
|
+
requiredPermissions: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
86
|
+
action: z.ZodOptional<z.ZodString>;
|
|
87
|
+
}, z.core.$strip>;
|
|
88
|
+
};
|
|
89
|
+
};
|
|
30
90
|
/**
|
|
31
91
|
* Schema creators for contract-based plugins
|
|
32
92
|
*/
|
|
33
|
-
export declare function createPluginInputSchema<TContract, TStateSchema extends z.ZodTypeAny>(contract: TContract, stateSchema: TStateSchema): z.ZodDiscriminatedUnion<[z.ZodObject<any, z.core.$strip>, ...z.ZodObject<any, z.core.$strip>[]], "procedure">;
|
|
34
|
-
export declare function createPluginOutputSchema<TContract, TStateSchema extends z.ZodTypeAny>(contract: TContract, stateSchema: TStateSchema): z.ZodUnion<[z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>, ...z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>[]]>;
|
|
93
|
+
export declare function createPluginInputSchema<TContract extends Contract, TStateSchema extends z.ZodTypeAny>(contract: TContract, stateSchema: TStateSchema): z.ZodDiscriminatedUnion<[z.ZodObject<any, z.core.$strip>, ...z.ZodObject<any, z.core.$strip>[]], "procedure">;
|
|
94
|
+
export declare function createPluginOutputSchema<TContract extends Contract, TStateSchema extends z.ZodTypeAny>(contract: TContract, stateSchema: TStateSchema): z.ZodUnion<[z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>, ...z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>[]]>;
|
|
35
95
|
/**
|
|
36
96
|
* Unified Plugin interface for all plugin types
|
|
37
97
|
*/
|
|
38
|
-
export interface Plugin<TContract
|
|
98
|
+
export interface Plugin<TContract extends Contract, TConfigSchema extends z.ZodTypeAny = z.ZodTypeAny, TStateSchema extends z.ZodTypeAny = z.ZodNull> {
|
|
39
99
|
readonly id: string;
|
|
40
100
|
readonly type: PluginType;
|
|
41
101
|
readonly contract: TContract;
|
|
@@ -43,9 +103,9 @@ export interface Plugin<TContract = Record<string, any>, TConfigSchema extends z
|
|
|
43
103
|
readonly stateSchema: TStateSchema;
|
|
44
104
|
readonly inputSchema: ReturnType<typeof createPluginInputSchema<TContract, TStateSchema>>;
|
|
45
105
|
readonly outputSchema: ReturnType<typeof createPluginOutputSchema<TContract, TStateSchema>>;
|
|
46
|
-
initialize(config?: z.infer<TConfigSchema>): Effect.Effect<void,
|
|
106
|
+
initialize(config?: z.infer<TConfigSchema>): Effect.Effect<void, PluginConfigurationError, PluginLoggerTag>;
|
|
47
107
|
shutdown(): Effect.Effect<void, never, PluginLoggerTag>;
|
|
48
|
-
createRouter():
|
|
108
|
+
createRouter(): Contract;
|
|
49
109
|
isStreamable(procedureName: string): boolean;
|
|
50
110
|
}
|
|
51
111
|
/**
|
|
@@ -80,16 +140,16 @@ export declare const pipe: <T>(value: T, ...fns: Array<(val: T) => T>) => T;
|
|
|
80
140
|
* Simple plugin base class that uses pure oRPC patterns
|
|
81
141
|
* Plugin just needs to define contract, config, and create oRPC router
|
|
82
142
|
*/
|
|
83
|
-
export declare abstract class SimplePlugin<TContract, TConfigSchema extends z.ZodTypeAny, TStateSchema extends z.ZodTypeAny = z.ZodNull> implements Plugin<TContract, TConfigSchema, TStateSchema> {
|
|
143
|
+
export declare abstract class SimplePlugin<TContract extends Contract, TConfigSchema extends z.ZodTypeAny, TStateSchema extends z.ZodTypeAny = z.ZodNull> implements Plugin<TContract, TConfigSchema, TStateSchema> {
|
|
84
144
|
abstract readonly id: string;
|
|
85
145
|
abstract readonly type: PluginType;
|
|
86
146
|
abstract readonly contract: TContract;
|
|
87
147
|
abstract readonly configSchema: TConfigSchema;
|
|
88
|
-
readonly stateSchema: TStateSchema;
|
|
148
|
+
abstract readonly stateSchema: TStateSchema;
|
|
89
149
|
get inputSchema(): z.ZodDiscriminatedUnion<[z.ZodObject<any, z.core.$strip>, ...z.ZodObject<any, z.core.$strip>[]], "procedure">;
|
|
90
150
|
get outputSchema(): z.ZodUnion<[z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>, ...z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>[]]>;
|
|
91
|
-
initialize(config?: z.infer<TConfigSchema>): Effect.Effect<void,
|
|
92
|
-
abstract createRouter():
|
|
151
|
+
initialize(config?: z.infer<TConfigSchema>): Effect.Effect<void, PluginConfigurationError, PluginLoggerTag>;
|
|
152
|
+
abstract createRouter(): Contract;
|
|
93
153
|
shutdown(): Effect.Effect<void, never, PluginLoggerTag>;
|
|
94
154
|
isStreamable(procedureName: string): boolean;
|
|
95
155
|
}
|
package/dist/plugin.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.ts","sourceRoot":"","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ACjC,SAAS,SAAS,QAAQ,EAC1B,aAAa,SAAS,CAAC,CAAC,UAAU,EAClC,YAAY,SAAS,CAAC,CAAC,UAAU,GAAG,CAAC,CAAC,OAAO,CAC5C,YAAW,MAAM,CAAC,SAAS,EAAE,aAAa,EAAE,YAAY,CAAC;IAC1D,QAAQ,CAAC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;IACnC,QAAQ,CAAC,QAAQ,CAAC,QAAQ,EAAE,SAAS,CAAC;IACtC,QAAQ,CAAC,QAAQ,CAAC,YAAY,EAAE,aAAa,CAAC;IAC9C,QAAQ,CAAC,QAAQ,CAAC,WAAW,EAAE,YAAY,CAAC;IAG5C,IAAI,WAAW,kHAEd;IAED,IAAI,YAAY,wKAEf;IAGD,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,aAAa,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,wBAAwB,EAAE,eAAe,CAAC;IAK3G,QAAQ,CAAC,YAAY,IAAI,QAAQ;IAEjC,QAAQ,IAAI,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,EAAE,eAAe,CAAC;IAKvD,YAAY,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO;CAQ5C"}
|
package/dist/plugin.js
CHANGED
|
@@ -2,8 +2,8 @@ import { Context, Effect } from "effect";
|
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
export function createConfigSchema(variablesSchema, secretsSchema) {
|
|
4
4
|
return z.object({
|
|
5
|
-
variables: variablesSchema
|
|
6
|
-
secrets: secretsSchema
|
|
5
|
+
variables: variablesSchema,
|
|
6
|
+
secrets: secretsSchema
|
|
7
7
|
});
|
|
8
8
|
}
|
|
9
9
|
export function createStateSchema(pluginStateSchema) {
|
|
@@ -14,6 +14,56 @@ export function createStateSchema(pluginStateSchema) {
|
|
|
14
14
|
}
|
|
15
15
|
export class PluginLoggerTag extends Context.Tag("PluginLogger")() {
|
|
16
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* Common error schemas that all plugins can use
|
|
19
|
+
* These provide consistent error handling across the plugin ecosystem
|
|
20
|
+
*/
|
|
21
|
+
export const CommonPluginErrors = {
|
|
22
|
+
UNAUTHORIZED: {
|
|
23
|
+
data: z.object({
|
|
24
|
+
apiKeyProvided: z.boolean(),
|
|
25
|
+
provider: z.string().optional(),
|
|
26
|
+
authType: z.enum(['apiKey', 'oauth', 'token']).optional(),
|
|
27
|
+
})
|
|
28
|
+
},
|
|
29
|
+
RATE_LIMITED: {
|
|
30
|
+
data: z.object({
|
|
31
|
+
retryAfter: z.number().int().min(1),
|
|
32
|
+
remainingRequests: z.number().int().min(0).optional(),
|
|
33
|
+
resetTime: z.string().datetime().optional(),
|
|
34
|
+
limitType: z.enum(['requests', 'tokens', 'bandwidth']).optional(),
|
|
35
|
+
})
|
|
36
|
+
},
|
|
37
|
+
SERVICE_UNAVAILABLE: {
|
|
38
|
+
data: z.object({
|
|
39
|
+
retryAfter: z.number().int().optional(),
|
|
40
|
+
maintenanceWindow: z.boolean().default(false),
|
|
41
|
+
estimatedUptime: z.string().datetime().optional(),
|
|
42
|
+
})
|
|
43
|
+
},
|
|
44
|
+
BAD_REQUEST: {
|
|
45
|
+
data: z.object({
|
|
46
|
+
invalidFields: z.array(z.string()).optional(),
|
|
47
|
+
validationErrors: z.array(z.object({
|
|
48
|
+
field: z.string(),
|
|
49
|
+
message: z.string(),
|
|
50
|
+
code: z.string().optional(),
|
|
51
|
+
})).optional(),
|
|
52
|
+
})
|
|
53
|
+
},
|
|
54
|
+
NOT_FOUND: {
|
|
55
|
+
data: z.object({
|
|
56
|
+
resource: z.string().optional(),
|
|
57
|
+
resourceId: z.string().optional(),
|
|
58
|
+
})
|
|
59
|
+
},
|
|
60
|
+
FORBIDDEN: {
|
|
61
|
+
data: z.object({
|
|
62
|
+
requiredPermissions: z.array(z.string()).optional(),
|
|
63
|
+
action: z.string().optional(),
|
|
64
|
+
})
|
|
65
|
+
}
|
|
66
|
+
};
|
|
17
67
|
/**
|
|
18
68
|
* Schema creators for contract-based plugins
|
|
19
69
|
*/
|
|
@@ -30,8 +80,10 @@ export function createPluginInputSchema(contract, stateSchema) {
|
|
|
30
80
|
input: inputSchema,
|
|
31
81
|
});
|
|
32
82
|
// Only add state field for streamable procedures
|
|
83
|
+
// Allow null state for initial calls to streamable procedures
|
|
84
|
+
const stateInputSchema = stateSchema.nullable();
|
|
33
85
|
return isStreamable
|
|
34
|
-
? baseSchema.extend({ state:
|
|
86
|
+
? baseSchema.extend({ state: stateInputSchema })
|
|
35
87
|
: baseSchema;
|
|
36
88
|
});
|
|
37
89
|
return z.discriminatedUnion("procedure", procedureSchemas);
|
|
@@ -81,7 +133,6 @@ export const pipe = (value, ...fns) => fns.reduce((acc, fn) => fn(acc), value);
|
|
|
81
133
|
* Plugin just needs to define contract, config, and create oRPC router
|
|
82
134
|
*/
|
|
83
135
|
export class SimplePlugin {
|
|
84
|
-
stateSchema = z.null();
|
|
85
136
|
// Auto-generated schemas
|
|
86
137
|
get inputSchema() {
|
|
87
138
|
return createPluginInputSchema(this.contract, this.stateSchema);
|
package/dist/runtime/errors.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
import { ORPCError } from "@orpc/contract";
|
|
1
2
|
import type { z } from "zod";
|
|
2
3
|
declare const PluginRuntimeError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => import("effect/Cause").YieldableError & {
|
|
3
4
|
readonly _tag: "PluginRuntimeError";
|
|
4
5
|
} & Readonly<A>;
|
|
5
6
|
export declare class PluginRuntimeError extends PluginRuntimeError_base<{
|
|
6
7
|
readonly pluginId?: string;
|
|
7
|
-
readonly operation
|
|
8
|
+
readonly operation?: string;
|
|
9
|
+
readonly procedureName?: string;
|
|
8
10
|
readonly cause?: Error;
|
|
9
11
|
readonly retryable: boolean;
|
|
10
12
|
}> {
|
|
@@ -41,5 +43,8 @@ export declare class StreamError extends StreamError_base<{
|
|
|
41
43
|
};
|
|
42
44
|
}> {
|
|
43
45
|
}
|
|
46
|
+
export declare const isRetryableORPCCode: (code: string) => boolean;
|
|
47
|
+
export declare const wrapORPCError: (orpcError: ORPCError<string, unknown>, pluginId?: string, procedureName?: string, operation?: string) => PluginRuntimeError;
|
|
48
|
+
export declare const toPluginRuntimeError: (error: unknown, pluginId?: string, procedureName?: string, operation?: string, defaultRetryable?: boolean) => PluginRuntimeError;
|
|
44
49
|
export {};
|
|
45
50
|
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/runtime/errors.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/runtime/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE3C,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;;;;AAE7B,qBAAa,kBAAmB,SAAQ,wBAAuC;IAC9E,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC;IACvB,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;CAC5B,CAAC;CAAI;;;;AAEN,qBAAa,qBAAsB,SAAQ,2BAEzC;IACD,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC;CACvB,CAAC;CAAI;;;;AAEN,qBAAa,eAAgB,SAAQ,qBAAoC;IACxE,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,KAAK,EAAE,QAAQ,GAAG,OAAO,GAAG,QAAQ,GAAG,OAAO,CAAC;IACxD,QAAQ,CAAC,QAAQ,EAAE,CAAC,CAAC,QAAQ,CAAC;CAC9B,CAAC;CAAI;;;;AAEN,qBAAa,WAAY,SAAQ,iBAAgC;IAChE,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,SAAS,EAAE,UAAU,GAAG,kBAAkB,GAAG,iBAAiB,GAAG,oBAAoB,CAAC;IAC/F,QAAQ,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC;IACvB,QAAQ,CAAC,OAAO,CAAC,EAAE;QAClB,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;QAC5B,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC;QACjC,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;KAChC,CAAC;CACF,CAAC;CAAI;AAGN,eAAO,MAAM,mBAAmB,GAAI,MAAM,MAAM,KAAG,OAWlD,CAAC;AAGF,eAAO,MAAM,aAAa,GACzB,WAAW,SAAS,CAAC,MAAM,EAAE,OAAO,CAAC,EACrC,WAAW,MAAM,EACjB,gBAAgB,MAAM,EACtB,YAAY,MAAM,KAChB,kBAQF,CAAC;AAGF,eAAO,MAAM,oBAAoB,GAChC,OAAO,OAAO,EACd,WAAW,MAAM,EACjB,gBAAgB,MAAM,EACtB,YAAY,MAAM,EAClB,0BAAwB,KACtB,kBAgBF,CAAC"}
|
package/dist/runtime/errors.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ORPCError } from "@orpc/contract";
|
|
1
2
|
import { Data } from "effect";
|
|
2
3
|
export class PluginRuntimeError extends Data.TaggedError("PluginRuntimeError") {
|
|
3
4
|
}
|
|
@@ -7,3 +8,42 @@ export class ValidationError extends Data.TaggedError("ValidationError") {
|
|
|
7
8
|
}
|
|
8
9
|
export class StreamError extends Data.TaggedError("StreamError") {
|
|
9
10
|
}
|
|
11
|
+
// Helper to determine if an oRPC error code is retryable
|
|
12
|
+
export const isRetryableORPCCode = (code) => {
|
|
13
|
+
switch (code) {
|
|
14
|
+
case 'TOO_MANY_REQUESTS':
|
|
15
|
+
case 'SERVICE_UNAVAILABLE':
|
|
16
|
+
case 'BAD_GATEWAY':
|
|
17
|
+
case 'GATEWAY_TIMEOUT':
|
|
18
|
+
case 'TIMEOUT':
|
|
19
|
+
return true;
|
|
20
|
+
default:
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
// Convert ORPC errors from plugin procedures to PluginRuntimeError
|
|
25
|
+
export const wrapORPCError = (orpcError, pluginId, procedureName, operation) => {
|
|
26
|
+
return new PluginRuntimeError({
|
|
27
|
+
pluginId,
|
|
28
|
+
operation,
|
|
29
|
+
procedureName,
|
|
30
|
+
retryable: isRetryableORPCCode(orpcError.code),
|
|
31
|
+
cause: orpcError
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
// Universal error converter for the runtime
|
|
35
|
+
export const toPluginRuntimeError = (error, pluginId, procedureName, operation, defaultRetryable = false) => {
|
|
36
|
+
if (error instanceof ORPCError) {
|
|
37
|
+
return wrapORPCError(error, pluginId, procedureName, operation);
|
|
38
|
+
}
|
|
39
|
+
if (error instanceof PluginRuntimeError) {
|
|
40
|
+
return error; // Already converted
|
|
41
|
+
}
|
|
42
|
+
return new PluginRuntimeError({
|
|
43
|
+
pluginId,
|
|
44
|
+
operation,
|
|
45
|
+
procedureName,
|
|
46
|
+
retryable: defaultRetryable,
|
|
47
|
+
cause: error instanceof Error ? error : new Error(String(error))
|
|
48
|
+
});
|
|
49
|
+
};
|
package/dist/runtime/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Effect, Layer, ManagedRuntime, type Stream } from "effect";
|
|
2
2
|
import type { z } from "zod";
|
|
3
|
-
import { type Plugin } from "../plugin";
|
|
3
|
+
import { Contract, type Plugin } from "../plugin";
|
|
4
4
|
import { PluginRuntimeError } from "./errors";
|
|
5
5
|
import { type StreamingOptions } from "./streaming";
|
|
6
6
|
import type { AnyPlugin, InitializedPlugin, PluginConstructor, PluginInstance, PluginRuntimeConfig } from "./types";
|
|
@@ -10,7 +10,7 @@ export interface IPluginRuntime {
|
|
|
10
10
|
readonly initializePlugin: <T extends AnyPlugin>(instance: PluginInstance<T>, config: z.infer<T["configSchema"]>) => Effect.Effect<InitializedPlugin<T>, PluginRuntimeError>;
|
|
11
11
|
readonly executePlugin: <T extends AnyPlugin>(initializedPlugin: InitializedPlugin<T>, input: z.infer<T["inputSchema"]>) => Effect.Effect<z.infer<T["outputSchema"]>, PluginRuntimeError>;
|
|
12
12
|
readonly usePlugin: <T extends AnyPlugin>(pluginId: string, config: z.infer<T["configSchema"]>) => Effect.Effect<InitializedPlugin<T>, PluginRuntimeError>;
|
|
13
|
-
readonly streamPlugin: <T extends Plugin
|
|
13
|
+
readonly streamPlugin: <T extends Plugin<Contract>, TInput extends z.infer<T["inputSchema"]> = z.infer<T["inputSchema"]>, TItem = unknown, TPluginState extends z.infer<T["stateSchema"]> = z.infer<T["stateSchema"]>>(pluginId: string, config: z.infer<T["configSchema"]>, input: TInput, options?: StreamingOptions<TItem, TPluginState>) => Effect.Effect<Stream.Stream<TItem, PluginRuntimeError>, PluginRuntimeError>;
|
|
14
14
|
readonly shutdown: () => Effect.Effect<void, never, never>;
|
|
15
15
|
}
|
|
16
16
|
declare const PluginRuntime_base: import("effect/Context").TagClass<PluginRuntime, "PluginRuntime", IPluginRuntime> & Effect.Tag.Proxy<PluginRuntime, IPluginRuntime> & {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/runtime/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,KAAK,E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E,MAAM,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;CAC3D;;;;AAED,qBAAa,aAAc,SAAQ,kBAGhC;IACF,MAAM,CAAC,IAAI,GAAI,QAAQ,mBAAmB,8CA8CzC;CACD;AAED,eAAO,MAAM,mBAAmB,GAAI,QAAQ,mBAAmB,wDACf,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"module-federation.service.d.ts","sourceRoot":"","sources":["../../../src/runtime/services/module-federation.service.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"module-federation.service.d.ts","sourceRoot":"","sources":["../../../src/runtime/services/module-federation.service.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AACvC,OAAO,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AASlD,MAAM,WAAW,wBAAwB;IACxC,QAAQ,CAAC,cAAc,EAAE,CACxB,QAAQ,EAAE,MAAM,EAChB,GAAG,EAAE,MAAM,KACP,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,qBAAqB,CAAC,CAAC;IAChD,QAAQ,CAAC,qBAAqB,EAAE,CAC/B,QAAQ,EAAE,MAAM,EAChB,GAAG,EAAE,MAAM,KACP,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,qBAAqB,CAAC,CAAC;CAC/C;;;;AAiED,qBAAa,uBAAwB,SAAQ,4BAES;IACrD,MAAM,CAAC,IAAI,qDA4FT;CACF;AAED,eAAO,MAAM,0BAA0B,gCAA0B,CAAC;AAClE,eAAO,MAAM,2BAA2B,oDAA+B,CAAC"}
|
|
@@ -17,54 +17,46 @@ const createModuleFederationInstance = Effect.cached(Effect.sync(() => {
|
|
|
17
17
|
name: "host",
|
|
18
18
|
remotes: [],
|
|
19
19
|
shared: {
|
|
20
|
-
|
|
21
|
-
shareConfig: {
|
|
22
|
-
singleton: true,
|
|
23
|
-
requiredVersion: "^3.17.0",
|
|
24
|
-
eager: false,
|
|
25
|
-
strictVersion: false,
|
|
26
|
-
},
|
|
27
|
-
},
|
|
28
|
-
zod: {
|
|
20
|
+
"every-plugin": {
|
|
29
21
|
shareConfig: {
|
|
30
22
|
singleton: true,
|
|
31
|
-
requiredVersion:
|
|
32
|
-
eager:
|
|
23
|
+
requiredVersion: false,
|
|
24
|
+
eager: true,
|
|
33
25
|
strictVersion: false,
|
|
34
26
|
},
|
|
35
27
|
},
|
|
36
|
-
|
|
28
|
+
effect: {
|
|
37
29
|
shareConfig: {
|
|
38
30
|
singleton: true,
|
|
39
|
-
requiredVersion:
|
|
40
|
-
eager:
|
|
31
|
+
requiredVersion: false,
|
|
32
|
+
eager: true,
|
|
41
33
|
strictVersion: false,
|
|
42
34
|
},
|
|
43
35
|
},
|
|
44
|
-
|
|
36
|
+
zod: {
|
|
45
37
|
shareConfig: {
|
|
46
38
|
singleton: true,
|
|
47
|
-
requiredVersion:
|
|
48
|
-
eager:
|
|
39
|
+
requiredVersion: false,
|
|
40
|
+
eager: true,
|
|
49
41
|
strictVersion: false,
|
|
50
42
|
},
|
|
51
43
|
},
|
|
52
|
-
"@
|
|
44
|
+
"@orpc/contract": {
|
|
53
45
|
shareConfig: {
|
|
54
46
|
singleton: true,
|
|
55
|
-
requiredVersion:
|
|
56
|
-
eager:
|
|
47
|
+
requiredVersion: false,
|
|
48
|
+
eager: true,
|
|
57
49
|
strictVersion: false,
|
|
58
50
|
},
|
|
59
51
|
},
|
|
60
|
-
"@
|
|
52
|
+
"@orpc/server": {
|
|
61
53
|
shareConfig: {
|
|
62
54
|
singleton: true,
|
|
63
|
-
requiredVersion:
|
|
64
|
-
eager:
|
|
55
|
+
requiredVersion: false,
|
|
56
|
+
eager: true,
|
|
65
57
|
strictVersion: false,
|
|
66
58
|
},
|
|
67
|
-
}
|
|
59
|
+
}
|
|
68
60
|
},
|
|
69
61
|
});
|
|
70
62
|
setGlobalFederationInstance(instance);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Effect, Layer, type Stream } from "effect";
|
|
2
2
|
import type { z } from "zod";
|
|
3
|
-
import { type Plugin, PluginLoggerTag, type PluginRegistry } from "../../plugin";
|
|
3
|
+
import { type Contract, type Plugin, PluginLoggerTag, type PluginRegistry } from "../../plugin";
|
|
4
4
|
import { PluginRuntimeError } from "../errors";
|
|
5
5
|
import { type StreamingOptions } from "../streaming";
|
|
6
6
|
import type { AnyPlugin, InitializedPlugin, PluginConstructor, PluginInstance, SecretsConfig } from "../types";
|
|
@@ -12,7 +12,7 @@ export interface IPluginService {
|
|
|
12
12
|
readonly initializePlugin: <T extends AnyPlugin>(pluginInstance: PluginInstance<T>, config: unknown) => Effect.Effect<InitializedPlugin<T>, PluginRuntimeError>;
|
|
13
13
|
readonly executePlugin: <T extends AnyPlugin>(initializedPlugin: InitializedPlugin<T>, input: z.infer<T["inputSchema"]>) => Effect.Effect<z.infer<T["outputSchema"]>, PluginRuntimeError>;
|
|
14
14
|
readonly usePlugin: <T extends AnyPlugin>(pluginId: string, config: unknown) => Effect.Effect<InitializedPlugin<T>, PluginRuntimeError>;
|
|
15
|
-
readonly streamPlugin: <T extends Plugin
|
|
15
|
+
readonly streamPlugin: <T extends Plugin<Contract>, TInput extends z.infer<T["inputSchema"]> = z.infer<T["inputSchema"]>, TItem = unknown, TPluginState extends z.infer<T["stateSchema"]> = z.infer<T["stateSchema"]>>(pluginId: string, config: z.infer<T["configSchema"]>, input: TInput, options?: StreamingOptions<TItem, TPluginState>) => Effect.Effect<Stream.Stream<TItem, PluginRuntimeError>, PluginRuntimeError>;
|
|
16
16
|
readonly shutdownPlugin: (plugin: InitializedPlugin<AnyPlugin>) => Effect.Effect<void, PluginRuntimeError>;
|
|
17
17
|
readonly clearCache: () => Effect.Effect<void, never>;
|
|
18
18
|
readonly cleanup: () => Effect.Effect<void, never>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.service.d.ts","sourceRoot":"","sources":["../../../src/runtime/services/plugin.service.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"plugin.service.d.ts","sourceRoot":"","sources":["../../../src/runtime/services/plugin.service.ts"],"names":[],"mappings":"AAEA,OAAO,EAAmB,MAAM,EAAQ,KAAK,EAAY,KAAK,MAAM,EAAE,MAAM,QAAQ,CAAC;AACrF,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAC7B,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,MAAM,EAAE,eAAe,EAAE,KAAK,cAAc,EAAE,MAAM,cAAc,CAAC;AAChG,OAAO,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,EAAsB,KAAK,gBAAgB,EAAE,MAAM,cAAc,CAAC;AACzE,OAAO,KAAK,EACX,SAAS,EACT,iBAAiB,EACjB,iBAAiB,EACjB,cAAc,EACd,aAAa,EACb,MAAM,UAAU,CAAC;AAElB,OAAO,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AACtE,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAEnD,MAAM,WAAW,cAAc;IAC9B,QAAQ,CAAC,UAAU,EAAE,CACpB,QAAQ,EAAE,MAAM,KACZ,MAAM,CAAC,MAAM,CAAC,iBAAiB,EAAE,kBAAkB,CAAC,CAAC;IAC1D,QAAQ,CAAC,iBAAiB,EAAE,CAAC,CAAC,SAAS,SAAS,EAC/C,iBAAiB,EAAE,iBAAiB,KAChC,MAAM,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC,CAAC,EAAE,kBAAkB,CAAC,CAAC;IAC1D,QAAQ,CAAC,gBAAgB,EAAE,CAAC,CAAC,SAAS,SAAS,EAC9C,cAAc,EAAE,cAAc,CAAC,CAAC,CAAC,EACjC,MAAM,EAAE,OAAO,KACX,MAAM,CAAC,MAAM,CAAC,iBAAiB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iB,CAAC,SAAS,CAAC,KAAK,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,kBAAkB,CAAC,CAAC;IAC3G,QAAQ,CAAC,UAAU,EAAE,MAAM,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IACtD,QAAQ,CAAC,OAAO,EAAE,MAAM,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;CACnD;;;;AAED,qBAAa,aAAc,SAAQ,kBAGhC;IACF,MAAM,CAAC,IAAI,GAAI,UAAU,cAAc,EAAE,SAAS,aAAa,mGA2c5D;CACH;AAED,eAAO,MAAM,gBAAgB,sBAAgB,CAAC;AAC9C,eAAO,MAAM,iBAAiB,aA/cJ,cAAc,WAAW,aAAa,kGA+cb,CAAC"}
|
|
@@ -177,6 +177,7 @@ export class PluginService extends Effect.Tag("PluginService")() {
|
|
|
177
177
|
const output = yield* Effect.tryPromise({
|
|
178
178
|
try: () => {
|
|
179
179
|
const procedure = router[procedureName];
|
|
180
|
+
;
|
|
180
181
|
if (!procedure) {
|
|
181
182
|
throw new Error(`Procedure ${procedureName} not found in router`);
|
|
182
183
|
}
|
|
@@ -220,8 +221,9 @@ export class PluginService extends Effect.Tag("PluginService")() {
|
|
|
220
221
|
retryable: false,
|
|
221
222
|
}));
|
|
222
223
|
}
|
|
223
|
-
// Validate initial state
|
|
224
|
-
|
|
224
|
+
// Validate initial state - allow null for initial calls
|
|
225
|
+
const nullableStateSchema = initializedPlugin.plugin.stateSchema.nullable();
|
|
226
|
+
yield* validate(nullableStateSchema, input.state, initializedPlugin.plugin.id, "state").pipe(Effect.mapError((validationError) => new PluginRuntimeError({
|
|
225
227
|
pluginId: initializedPlugin.plugin.id,
|
|
226
228
|
operation: "validate-state",
|
|
227
229
|
cause: validationError.zodError,
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Effect, Stream } from "effect";
|
|
2
2
|
import type { z } from "zod";
|
|
3
|
-
import type { Plugin } from "../../plugin";
|
|
4
|
-
import type
|
|
3
|
+
import type { Contract, Plugin } from "../../plugin";
|
|
4
|
+
import { type PluginRuntimeError } from "../errors";
|
|
5
5
|
import type { InitializedPlugin } from "../types";
|
|
6
6
|
import type { StreamingOptions } from "./types";
|
|
7
|
-
export declare const createSourceStream: <T extends Plugin
|
|
7
|
+
export declare const createSourceStream: <T extends Plugin<Contract>, TInput extends z.infer<T["inputSchema"]>, TItem, TPluginState extends z.infer<T["stateSchema"]>>(initializedPlugin: InitializedPlugin<T>, executePlugin: (plugin: InitializedPlugin<T>, input: TInput) => Effect.Effect<z.infer<T["outputSchema"]>, PluginRuntimeError>, input: TInput, options?: StreamingOptions<TItem, TPluginState>) => Stream.Stream<TItem, PluginRuntimeError>;
|
|
8
8
|
//# sourceMappingURL=streaming.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"streaming.d.ts","sourceRoot":"","sources":["../../../src/runtime/streaming/streaming.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,MAAM,
|
|
1
|
+
{"version":3,"file":"streaming.d.ts","sourceRoot":"","sources":["../../../src/runtime/streaming/streaming.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAClD,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAC7B,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,EAAE,KAAK,kBAAkB,EAAwB,MAAM,WAAW,CAAC;AAC1E,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAClD,OAAO,KAAK,EAAE,gBAAgB,EAAe,MAAM,SAAS,CAAC;AAsB7D,eAAO,MAAM,kBAAkB,GAC7B,CAAC,SAAS,MAAM,CAAC,QAAQ,CAAC,EAC1B,MAAM,SAAS,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,EACxC,KAAK,EACL,YAAY,SAAS,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,EAE9C,mBAAmB,iBAAiB,CAAC,CAAC,CAAC,EACvC,eAAe,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,EAAE,kBAAkB,CAAC,EAC7H,OAAO,MAAM,EACb,UAAS,gBAAgB,CAAC,KAAK,EAAE,YAAY,CAAM,KAClD,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,kBAAkB,CAuHzC,CAAC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Duration, Effect, Stream } from "effect";
|
|
2
|
+
import { toPluginRuntimeError } from "../errors";
|
|
2
3
|
/**
|
|
3
4
|
* Extract delay from plugin state (nextPollMs field)
|
|
4
5
|
* Returns null if nextPollMs is null (signals termination) or undefined (no delay specified)
|
|
@@ -49,7 +50,9 @@ export const createSourceStream = (initializedPlugin, executePlugin, input, opti
|
|
|
49
50
|
};
|
|
50
51
|
console.log(`[STREAMING] About to execute plugin with input:`, JSON.stringify(pluginInput, null, 2));
|
|
51
52
|
console.log(`[STREAMING] Plugin state:`, JSON.stringify(currentStreamState.pluginState, null, 2));
|
|
52
|
-
const rawResult = await Effect.runPromise(executePlugin(initializedPlugin, pluginInput))
|
|
53
|
+
const rawResult = await Effect.runPromise(executePlugin(initializedPlugin, pluginInput).pipe(Effect.catchAll((error) => {
|
|
54
|
+
return toPluginRuntimeError(error);
|
|
55
|
+
})));
|
|
53
56
|
console.log(`[STREAMING] Plugin execution completed`);
|
|
54
57
|
// Transform raw plugin result to streaming format
|
|
55
58
|
const resultObj = rawResult;
|
|
@@ -65,7 +68,10 @@ export const createSourceStream = (initializedPlugin, executePlugin, input, opti
|
|
|
65
68
|
console.log(`[STREAMING] Invocation ${currentStreamState.invocations}, Items: ${items.length}`);
|
|
66
69
|
// Call state change hook if provided
|
|
67
70
|
if (options.onStateChange) {
|
|
68
|
-
await Effect.runPromise(options.onStateChange(nextPluginState, items))
|
|
71
|
+
await Effect.runPromise(options.onStateChange(nextPluginState, items).pipe(Effect.catchAll((error) => {
|
|
72
|
+
console.warn(`[STREAMING] onStateChange failed:`, error);
|
|
73
|
+
return Effect.void;
|
|
74
|
+
})));
|
|
69
75
|
}
|
|
70
76
|
// Emit items immediately (before any delays)
|
|
71
77
|
for (const item of items) {
|
|
@@ -14,6 +14,6 @@ export interface StreamingOptions<TItem = unknown, TPluginState = unknown> {
|
|
|
14
14
|
maxItems?: number;
|
|
15
15
|
maxInvocations?: number;
|
|
16
16
|
stopWhenEmpty?: boolean;
|
|
17
|
-
onStateChange?: (newPluginState: TPluginState, items: TItem[]) => Effect.Effect<void>;
|
|
17
|
+
onStateChange?: (newPluginState: TPluginState, items: TItem[]) => Effect.Effect<void, Error>;
|
|
18
18
|
}
|
|
19
19
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/runtime/streaming/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAErC;;GAEG;AACH,MAAM,WAAW,WAAW,CAAC,YAAY;IACvC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,WAAW,EAAE,YAAY,CAAC;IACnC,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;CAChC;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB,CAAC,KAAK,GAAG,OAAO,EAAE,YAAY,GAAG,OAAO;IACvE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,aAAa,CAAC,EAAE,OAAO,CAAC;IAGxB,aAAa,CAAC,EAAE,CAAC,cAAc,EAAE,YAAY,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/runtime/streaming/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAErC;;GAEG;AACH,MAAM,WAAW,WAAW,CAAC,YAAY;IACvC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,WAAW,EAAE,YAAY,CAAC;IACnC,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;CAChC;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB,CAAC,KAAK,GAAG,OAAO,EAAE,YAAY,GAAG,OAAO;IACvE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,aAAa,CAAC,EAAE,OAAO,CAAC;IAGxB,aAAa,CAAC,EAAE,CAAC,cAAc,EAAE,YAAY,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;CAC9F"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "every-plugin",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"exports": {
|
|
@@ -32,32 +32,28 @@
|
|
|
32
32
|
"test:build-plugin": "cd __tests__/test-plugin && NODE_ENV=test npm run build"
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
35
|
-
"
|
|
36
|
-
"zod": ">=4.0.0",
|
|
37
|
-
"@module-federation/enhanced": ">=0.18.0",
|
|
38
|
-
"@module-federation/runtime-core": ">=0.18.0",
|
|
39
|
-
"@orpc/server": ">=0.0.1"
|
|
35
|
+
"typescript": "^5.0.0"
|
|
40
36
|
},
|
|
41
37
|
"devDependencies": {
|
|
42
38
|
"@effect/language-service": "^0.38.1",
|
|
43
39
|
"@effect/vitest": "^0.25.1",
|
|
44
|
-
"@module-federation/enhanced": "^0.18.3",
|
|
45
|
-
"@module-federation/node": "^2.7.15",
|
|
46
|
-
"@module-federation/runtime-core": "^0.18.3",
|
|
47
40
|
"@rspack/cli": "^1.5.2",
|
|
48
41
|
"@rspack/core": "^1.5.2",
|
|
49
42
|
"@types/bun": "^1.2.21",
|
|
50
43
|
"@types/node": "^24.3.1",
|
|
51
44
|
"@vitest/ui": "3.2.4",
|
|
52
45
|
"bun-types": "^1.2.21",
|
|
53
|
-
"effect": "^3.17.13",
|
|
54
46
|
"sirv": "^3.0.2",
|
|
55
|
-
"
|
|
56
|
-
"vitest": "^3.2.4",
|
|
57
|
-
"zod": "^4.1.5"
|
|
47
|
+
"vitest": "^3.2.4"
|
|
58
48
|
},
|
|
59
49
|
"dependencies": {
|
|
60
50
|
"@better-fetch/fetch": "^1.1.18",
|
|
61
|
-
"@
|
|
51
|
+
"@module-federation/enhanced": "^0.18.3",
|
|
52
|
+
"@module-federation/node": "^2.7.15",
|
|
53
|
+
"@module-federation/runtime-core": "^0.18.3",
|
|
54
|
+
"@orpc/contract": "^1.8.6",
|
|
55
|
+
"@orpc/server": "^1.8.6",
|
|
56
|
+
"effect": "^3.17.13",
|
|
57
|
+
"zod": "^4.1.5"
|
|
62
58
|
}
|
|
63
59
|
}
|