@stigmer/sdk 3.2.2 → 3.3.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/__tests__/errors.test.js +44 -1
- package/__tests__/errors.test.js.map +1 -1
- package/__tests__/manifest.test.d.ts +2 -0
- package/__tests__/manifest.test.d.ts.map +1 -0
- package/__tests__/manifest.test.js +229 -0
- package/__tests__/manifest.test.js.map +1 -0
- package/billing.d.ts +83 -1
- package/billing.d.ts.map +1 -1
- package/billing.js +91 -1
- package/billing.js.map +1 -1
- package/cursor-accounts.d.ts +94 -0
- package/cursor-accounts.d.ts.map +1 -0
- package/cursor-accounts.js +119 -0
- package/cursor-accounts.js.map +1 -0
- package/errors.d.ts +14 -0
- package/errors.d.ts.map +1 -1
- package/errors.js +26 -0
- package/errors.js.map +1 -1
- package/execution/approval-provenance.d.ts.map +1 -1
- package/execution/approval-provenance.js +7 -0
- package/execution/approval-provenance.js.map +1 -1
- package/gen/agent.d.ts +5 -0
- package/gen/agent.d.ts.map +1 -1
- package/gen/agent.js +9 -1
- package/gen/agent.js.map +1 -1
- package/gen/agentexecution.d.ts +3 -1
- package/gen/agentexecution.d.ts.map +1 -1
- package/gen/agentexecution.js +4 -0
- package/gen/agentexecution.js.map +1 -1
- package/gen/agentinstance.d.ts +1 -0
- package/gen/agentinstance.d.ts.map +1 -1
- package/gen/agentinstance.js +1 -0
- package/gen/agentinstance.js.map +1 -1
- package/gen/authorization-config.d.ts.map +1 -1
- package/gen/authorization-config.js +1 -0
- package/gen/authorization-config.js.map +1 -1
- package/gen/client.d.ts +6 -2
- package/gen/client.d.ts.map +1 -1
- package/gen/client.js +4 -0
- package/gen/client.js.map +1 -1
- package/gen/datastore.d.ts +128 -0
- package/gen/datastore.d.ts.map +1 -0
- package/gen/datastore.js +302 -0
- package/gen/datastore.js.map +1 -0
- package/gen/session.d.ts +1 -0
- package/gen/session.d.ts.map +1 -1
- package/gen/session.js +1 -0
- package/gen/session.js.map +1 -1
- package/index.d.ts +5 -3
- package/index.d.ts.map +1 -1
- package/index.js +7 -3
- package/index.js.map +1 -1
- package/manifest/client.d.ts +64 -0
- package/manifest/client.d.ts.map +1 -0
- package/manifest/client.js +109 -0
- package/manifest/client.js.map +1 -0
- package/manifest/index.d.ts +9 -0
- package/manifest/index.d.ts.map +1 -0
- package/manifest/index.js +11 -0
- package/manifest/index.js.map +1 -0
- package/manifest/parse.d.ts +57 -0
- package/manifest/parse.d.ts.map +1 -0
- package/manifest/parse.js +134 -0
- package/manifest/parse.js.map +1 -0
- package/manifest/redaction.d.ts +16 -0
- package/manifest/redaction.d.ts.map +1 -0
- package/manifest/redaction.js +19 -0
- package/manifest/redaction.js.map +1 -0
- package/manifest/registry.d.ts +44 -0
- package/manifest/registry.d.ts.map +1 -0
- package/manifest/registry.js +178 -0
- package/manifest/registry.js.map +1 -0
- package/manifest/serialize.d.ts +24 -0
- package/manifest/serialize.d.ts.map +1 -0
- package/manifest/serialize.js +78 -0
- package/manifest/serialize.js.map +1 -0
- package/package.json +4 -3
- package/src/__tests__/errors.test.ts +58 -0
- package/src/__tests__/manifest.test.ts +271 -0
- package/src/billing.ts +160 -0
- package/src/cursor-accounts.ts +207 -0
- package/src/errors.ts +27 -0
- package/src/execution/approval-provenance.ts +7 -0
- package/src/gen/agent.ts +15 -1
- package/src/gen/agentexecution.ts +5 -1
- package/src/gen/agentinstance.ts +2 -0
- package/src/gen/authorization-config.ts +1 -0
- package/src/gen/client.ts +7 -2
- package/src/gen/datastore.ts +379 -0
- package/src/gen/session.ts +2 -0
- package/src/index.ts +30 -0
- package/src/manifest/client.ts +145 -0
- package/src/manifest/index.ts +25 -0
- package/src/manifest/parse.ts +204 -0
- package/src/manifest/redaction.ts +20 -0
- package/src/manifest/registry.ts +232 -0
- package/src/manifest/serialize.ts +92 -0
- package/src/stigmer.ts +8 -0
- package/stigmer.d.ts +6 -0
- package/stigmer.d.ts.map +1 -1
- package/stigmer.js +8 -0
- package/stigmer.js.map +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redaction.js","sourceRoot":"","sources":["../../src/manifest/redaction.ts"],"names":[],"mappings":"AAAA,qEAAqE;AAErE;;;;;GAKG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,gBAAgB,CAAC;AAEvD;;;;;;GAMG;AACH,MAAM,UAAU,uBAAuB,CAAC,OAAe;IACrD,OAAO,OAAO,CAAC,QAAQ,CAAC,sBAAsB,CAAC,CAAC;AAClD,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { DescMessage, DescService, Message } from "@bufbuild/protobuf";
|
|
2
|
+
import type { Client } from "@connectrpc/connect";
|
|
3
|
+
import { ApiResourceKind } from "@stigmer/protos/ai/stigmer/commons/apiresource/apiresourcekind/api_resource_kind_pb";
|
|
4
|
+
import type { ApiResourceReference } from "@stigmer/protos/ai/stigmer/commons/apiresource/io_pb";
|
|
5
|
+
/**
|
|
6
|
+
* Accessor for a raw Connect client over a generated service controller.
|
|
7
|
+
* Implementations cache clients per service (see `ManifestClient`).
|
|
8
|
+
*/
|
|
9
|
+
export type ServiceClientFn = <Desc extends DescService>(service: Desc) => Client<Desc>;
|
|
10
|
+
/**
|
|
11
|
+
* Binds one YAML `kind` to everything the manifest engine needs:
|
|
12
|
+
* the proto schema (strict marshalling), the command controller's `apply`
|
|
13
|
+
* RPC, and the query controller's `getByReference` RPC (create-vs-update
|
|
14
|
+
* preview).
|
|
15
|
+
*/
|
|
16
|
+
export interface ManifestKindHandler {
|
|
17
|
+
/** The platform resource kind enum value. */
|
|
18
|
+
readonly kind: ApiResourceKind;
|
|
19
|
+
/** The YAML discriminator, e.g. `"Agent"`. */
|
|
20
|
+
readonly yamlKind: string;
|
|
21
|
+
/** Human-facing name for messages, e.g. `"MCP Server"`. */
|
|
22
|
+
readonly displayName: string;
|
|
23
|
+
/** Canonical `apiVersion` for this kind, e.g. `"agentic.stigmer.ai/v1"`. */
|
|
24
|
+
readonly apiVersion: string;
|
|
25
|
+
/** Proto schema for strict YAML↔proto conversion. */
|
|
26
|
+
readonly schema: DescMessage;
|
|
27
|
+
/**
|
|
28
|
+
* Position in the dependency apply order (ascending). Referenced kinds
|
|
29
|
+
* apply before their dependents, e.g. an McpServer before the Agent that
|
|
30
|
+
* uses it, and everything an AgentChannel references before the channel.
|
|
31
|
+
*/
|
|
32
|
+
readonly applyOrder: number;
|
|
33
|
+
/** Drive the command controller's `apply` RPC with the full resource. */
|
|
34
|
+
apply(clientFor: ServiceClientFn, message: Message): Promise<Message>;
|
|
35
|
+
/** Load the current server state by org/slug reference. */
|
|
36
|
+
getByReference(clientFor: ServiceClientFn, ref: ApiResourceReference): Promise<Message>;
|
|
37
|
+
}
|
|
38
|
+
/** All kinds the manifest engine supports, in dependency apply order. */
|
|
39
|
+
export declare function manifestKinds(): readonly ManifestKindHandler[];
|
|
40
|
+
/** Resolve a handler by its YAML `kind` discriminator (e.g. `"Agent"`). */
|
|
41
|
+
export declare function manifestHandlerForYamlKind(yamlKind: string): ManifestKindHandler | undefined;
|
|
42
|
+
/** Resolve a handler from a proto message's fully-qualified type name. */
|
|
43
|
+
export declare function manifestHandlerForTypeName(typeName: string): ManifestKindHandler | undefined;
|
|
44
|
+
//# sourceMappingURL=registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/manifest/registry.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC5E,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,qFAAqF,CAAC;AACtH,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,sDAAsD,CAAC;AAoCjG;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG,CAAC,IAAI,SAAS,WAAW,EAAE,OAAO,EAAE,IAAI,KAAK,MAAM,CAAC,IAAI,CAAC,CAAC;AAExF;;;;;GAKG;AACH,MAAM,WAAW,mBAAmB;IAClC,6CAA6C;IAC7C,QAAQ,CAAC,IAAI,EAAE,eAAe,CAAC;IAC/B,8CAA8C;IAC9C,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,2DAA2D;IAC3D,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,4EAA4E;IAC5E,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,qDAAqD;IACrD,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC;IAC7B;;;;OAIG;IACH,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,yEAAyE;IACzE,KAAK,CAAC,SAAS,EAAE,eAAe,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IACtE,2DAA2D;IAC3D,cAAc,CAAC,SAAS,EAAE,eAAe,EAAE,GAAG,EAAE,oBAAoB,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CACzF;AAiID,yEAAyE;AACzE,wBAAgB,aAAa,IAAI,SAAS,mBAAmB,EAAE,CAE9D;AAED,2EAA2E;AAC3E,wBAAgB,0BAA0B,CACxC,QAAQ,EAAE,MAAM,GACf,mBAAmB,GAAG,SAAS,CAEjC;AAED,0EAA0E;AAC1E,wBAAgB,0BAA0B,CACxC,QAAQ,EAAE,MAAM,GACf,mBAAmB,GAAG,SAAS,CAEjC"}
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
// Explicit manifest-kind registry: the single place that binds a YAML `kind`
|
|
2
|
+
// to its proto schema and controller RPCs.
|
|
3
|
+
//
|
|
4
|
+
// This is the SDK home of the pattern the CLIs already rely on (Go CLI,
|
|
5
|
+
// TS CLI `resources/apply/handlers.ts`, mcp-server): strict YAML→proto
|
|
6
|
+
// marshalling against the *generated schema*, and apply through the raw
|
|
7
|
+
// command controller with the full resource message. The high-level
|
|
8
|
+
// `*Input` wrappers are intentionally bypassed — they are lossy (they drop
|
|
9
|
+
// `metadata.id` and any field codegen hasn't projected), while the `apply`
|
|
10
|
+
// RPC takes the complete resource and the server upserts by slug.
|
|
11
|
+
//
|
|
12
|
+
// Registration is explicit — to support a new kind, add one entry here.
|
|
13
|
+
import { ApiResourceKind } from "@stigmer/protos/ai/stigmer/commons/apiresource/apiresourcekind/api_resource_kind_pb";
|
|
14
|
+
import { AgentSchema } from "@stigmer/protos/ai/stigmer/agentic/agent/v1/api_pb";
|
|
15
|
+
import { AgentCommandController } from "@stigmer/protos/ai/stigmer/agentic/agent/v1/command_pb";
|
|
16
|
+
import { AgentQueryController } from "@stigmer/protos/ai/stigmer/agentic/agent/v1/query_pb";
|
|
17
|
+
import { AgentChannelSchema } from "@stigmer/protos/ai/stigmer/agentic/agentchannel/v1/api_pb";
|
|
18
|
+
import { AgentChannelCommandController } from "@stigmer/protos/ai/stigmer/agentic/agentchannel/v1/command_pb";
|
|
19
|
+
import { AgentChannelQueryController } from "@stigmer/protos/ai/stigmer/agentic/agentchannel/v1/query_pb";
|
|
20
|
+
import { AgentInstanceSchema } from "@stigmer/protos/ai/stigmer/agentic/agentinstance/v1/api_pb";
|
|
21
|
+
import { AgentInstanceCommandController } from "@stigmer/protos/ai/stigmer/agentic/agentinstance/v1/command_pb";
|
|
22
|
+
import { AgentInstanceQueryController } from "@stigmer/protos/ai/stigmer/agentic/agentinstance/v1/query_pb";
|
|
23
|
+
import { AgentShareSchema } from "@stigmer/protos/ai/stigmer/agentic/agentshare/v1/api_pb";
|
|
24
|
+
import { AgentShareCommandController } from "@stigmer/protos/ai/stigmer/agentic/agentshare/v1/command_pb";
|
|
25
|
+
import { AgentShareQueryController } from "@stigmer/protos/ai/stigmer/agentic/agentshare/v1/query_pb";
|
|
26
|
+
import { ChannelAppSchema } from "@stigmer/protos/ai/stigmer/agentic/channelapp/v1/api_pb";
|
|
27
|
+
import { ChannelAppCommandController } from "@stigmer/protos/ai/stigmer/agentic/channelapp/v1/command_pb";
|
|
28
|
+
import { ChannelAppQueryController } from "@stigmer/protos/ai/stigmer/agentic/channelapp/v1/query_pb";
|
|
29
|
+
import { DatastoreSchema } from "@stigmer/protos/ai/stigmer/agentic/datastore/v1/api_pb";
|
|
30
|
+
import { DatastoreCommandController } from "@stigmer/protos/ai/stigmer/agentic/datastore/v1/command_pb";
|
|
31
|
+
import { DatastoreQueryController } from "@stigmer/protos/ai/stigmer/agentic/datastore/v1/query_pb";
|
|
32
|
+
import { EnvironmentSchema } from "@stigmer/protos/ai/stigmer/agentic/environment/v1/api_pb";
|
|
33
|
+
import { EnvironmentCommandController } from "@stigmer/protos/ai/stigmer/agentic/environment/v1/command_pb";
|
|
34
|
+
import { EnvironmentQueryController } from "@stigmer/protos/ai/stigmer/agentic/environment/v1/query_pb";
|
|
35
|
+
import { McpServerSchema } from "@stigmer/protos/ai/stigmer/agentic/mcpserver/v1/api_pb";
|
|
36
|
+
import { McpServerCommandController } from "@stigmer/protos/ai/stigmer/agentic/mcpserver/v1/command_pb";
|
|
37
|
+
import { McpServerQueryController } from "@stigmer/protos/ai/stigmer/agentic/mcpserver/v1/query_pb";
|
|
38
|
+
import { WorkflowSchema } from "@stigmer/protos/ai/stigmer/agentic/workflow/v1/api_pb";
|
|
39
|
+
import { WorkflowCommandController } from "@stigmer/protos/ai/stigmer/agentic/workflow/v1/command_pb";
|
|
40
|
+
import { WorkflowQueryController } from "@stigmer/protos/ai/stigmer/agentic/workflow/v1/query_pb";
|
|
41
|
+
import { IdentityProviderSchema } from "@stigmer/protos/ai/stigmer/iam/identityprovider/v1/api_pb";
|
|
42
|
+
import { IdentityProviderCommandController } from "@stigmer/protos/ai/stigmer/iam/identityprovider/v1/command_pb";
|
|
43
|
+
import { IdentityProviderQueryController } from "@stigmer/protos/ai/stigmer/iam/identityprovider/v1/query_pb";
|
|
44
|
+
import { OAuthAppSchema } from "@stigmer/protos/ai/stigmer/iam/oauthapp/v1/api_pb";
|
|
45
|
+
import { OAuthAppCommandController } from "@stigmer/protos/ai/stigmer/iam/oauthapp/v1/command_pb";
|
|
46
|
+
import { OAuthAppQueryController } from "@stigmer/protos/ai/stigmer/iam/oauthapp/v1/query_pb";
|
|
47
|
+
const AGENTIC_V1 = "agentic.stigmer.ai/v1";
|
|
48
|
+
const IAM_V1 = "iam.stigmer.ai/v1";
|
|
49
|
+
const HANDLERS = [
|
|
50
|
+
{
|
|
51
|
+
kind: ApiResourceKind.mcp_server,
|
|
52
|
+
yamlKind: "McpServer",
|
|
53
|
+
displayName: "MCP Server",
|
|
54
|
+
apiVersion: AGENTIC_V1,
|
|
55
|
+
schema: McpServerSchema,
|
|
56
|
+
applyOrder: 1,
|
|
57
|
+
apply: (c, m) => c(McpServerCommandController).apply(m),
|
|
58
|
+
getByReference: (c, ref) => c(McpServerQueryController).getByReference(ref),
|
|
59
|
+
},
|
|
60
|
+
// A Datastore applies before the Agents that reference it via
|
|
61
|
+
// datastore_usages (the McpServer-before-Agent pattern).
|
|
62
|
+
{
|
|
63
|
+
kind: ApiResourceKind.datastore,
|
|
64
|
+
yamlKind: "Datastore",
|
|
65
|
+
displayName: "Datastore",
|
|
66
|
+
apiVersion: AGENTIC_V1,
|
|
67
|
+
schema: DatastoreSchema,
|
|
68
|
+
applyOrder: 2,
|
|
69
|
+
apply: (c, m) => c(DatastoreCommandController).apply(m),
|
|
70
|
+
getByReference: (c, ref) => c(DatastoreQueryController).getByReference(ref),
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
kind: ApiResourceKind.agent,
|
|
74
|
+
yamlKind: "Agent",
|
|
75
|
+
displayName: "Agent",
|
|
76
|
+
apiVersion: AGENTIC_V1,
|
|
77
|
+
schema: AgentSchema,
|
|
78
|
+
applyOrder: 3,
|
|
79
|
+
apply: (c, m) => c(AgentCommandController).apply(m),
|
|
80
|
+
getByReference: (c, ref) => c(AgentQueryController).getByReference(ref),
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
kind: ApiResourceKind.workflow,
|
|
84
|
+
yamlKind: "Workflow",
|
|
85
|
+
displayName: "Workflow",
|
|
86
|
+
apiVersion: AGENTIC_V1,
|
|
87
|
+
schema: WorkflowSchema,
|
|
88
|
+
applyOrder: 4,
|
|
89
|
+
apply: (c, m) => c(WorkflowCommandController).apply(m),
|
|
90
|
+
getByReference: (c, ref) => c(WorkflowQueryController).getByReference(ref),
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
kind: ApiResourceKind.environment,
|
|
94
|
+
yamlKind: "Environment",
|
|
95
|
+
displayName: "Environment",
|
|
96
|
+
apiVersion: AGENTIC_V1,
|
|
97
|
+
schema: EnvironmentSchema,
|
|
98
|
+
applyOrder: 5,
|
|
99
|
+
apply: (c, m) => c(EnvironmentCommandController).apply(m),
|
|
100
|
+
getByReference: (c, ref) => c(EnvironmentQueryController).getByReference(ref),
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
kind: ApiResourceKind.identity_provider,
|
|
104
|
+
yamlKind: "IdentityProvider",
|
|
105
|
+
displayName: "Identity Provider",
|
|
106
|
+
apiVersion: IAM_V1,
|
|
107
|
+
schema: IdentityProviderSchema,
|
|
108
|
+
applyOrder: 6,
|
|
109
|
+
apply: (c, m) => c(IdentityProviderCommandController).apply(m),
|
|
110
|
+
getByReference: (c, ref) => c(IdentityProviderQueryController).getByReference(ref),
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
kind: ApiResourceKind.oauth_app,
|
|
114
|
+
yamlKind: "OAuthApp",
|
|
115
|
+
displayName: "OAuth App",
|
|
116
|
+
apiVersion: IAM_V1,
|
|
117
|
+
schema: OAuthAppSchema,
|
|
118
|
+
applyOrder: 7,
|
|
119
|
+
apply: (c, m) => c(OAuthAppCommandController).apply(m),
|
|
120
|
+
getByReference: (c, ref) => c(OAuthAppQueryController).getByReference(ref),
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
kind: ApiResourceKind.channel_app,
|
|
124
|
+
yamlKind: "ChannelApp",
|
|
125
|
+
displayName: "Channel App",
|
|
126
|
+
apiVersion: AGENTIC_V1,
|
|
127
|
+
schema: ChannelAppSchema,
|
|
128
|
+
applyOrder: 8,
|
|
129
|
+
apply: (c, m) => c(ChannelAppCommandController).apply(m),
|
|
130
|
+
getByReference: (c, ref) => c(ChannelAppQueryController).getByReference(ref),
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
kind: ApiResourceKind.agent_instance,
|
|
134
|
+
yamlKind: "AgentInstance",
|
|
135
|
+
displayName: "Agent Instance",
|
|
136
|
+
apiVersion: AGENTIC_V1,
|
|
137
|
+
schema: AgentInstanceSchema,
|
|
138
|
+
applyOrder: 9,
|
|
139
|
+
apply: (c, m) => c(AgentInstanceCommandController).apply(m),
|
|
140
|
+
getByReference: (c, ref) => c(AgentInstanceQueryController).getByReference(ref),
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
kind: ApiResourceKind.agent_share,
|
|
144
|
+
yamlKind: "AgentShare",
|
|
145
|
+
displayName: "Agent Share",
|
|
146
|
+
apiVersion: AGENTIC_V1,
|
|
147
|
+
schema: AgentShareSchema,
|
|
148
|
+
applyOrder: 10,
|
|
149
|
+
apply: (c, m) => c(AgentShareCommandController).apply(m),
|
|
150
|
+
getByReference: (c, ref) => c(AgentShareQueryController).getByReference(ref),
|
|
151
|
+
},
|
|
152
|
+
// Last: an AgentChannel references an Agent, a ChannelApp, and Environments.
|
|
153
|
+
{
|
|
154
|
+
kind: ApiResourceKind.agent_channel,
|
|
155
|
+
yamlKind: "AgentChannel",
|
|
156
|
+
displayName: "Agent Channel",
|
|
157
|
+
apiVersion: AGENTIC_V1,
|
|
158
|
+
schema: AgentChannelSchema,
|
|
159
|
+
applyOrder: 11,
|
|
160
|
+
apply: (c, m) => c(AgentChannelCommandController).apply(m),
|
|
161
|
+
getByReference: (c, ref) => c(AgentChannelQueryController).getByReference(ref),
|
|
162
|
+
},
|
|
163
|
+
];
|
|
164
|
+
const BY_YAML_KIND = new Map(HANDLERS.map((h) => [h.yamlKind, h]));
|
|
165
|
+
const BY_TYPE_NAME = new Map(HANDLERS.map((h) => [h.schema.typeName, h]));
|
|
166
|
+
/** All kinds the manifest engine supports, in dependency apply order. */
|
|
167
|
+
export function manifestKinds() {
|
|
168
|
+
return HANDLERS;
|
|
169
|
+
}
|
|
170
|
+
/** Resolve a handler by its YAML `kind` discriminator (e.g. `"Agent"`). */
|
|
171
|
+
export function manifestHandlerForYamlKind(yamlKind) {
|
|
172
|
+
return BY_YAML_KIND.get(yamlKind);
|
|
173
|
+
}
|
|
174
|
+
/** Resolve a handler from a proto message's fully-qualified type name. */
|
|
175
|
+
export function manifestHandlerForTypeName(typeName) {
|
|
176
|
+
return BY_TYPE_NAME.get(typeName);
|
|
177
|
+
}
|
|
178
|
+
//# sourceMappingURL=registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../../src/manifest/registry.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,2CAA2C;AAC3C,EAAE;AACF,wEAAwE;AACxE,uEAAuE;AACvE,wEAAwE;AACxE,oEAAoE;AACpE,2EAA2E;AAC3E,2EAA2E;AAC3E,kEAAkE;AAClE,EAAE;AACF,wEAAwE;AAIxE,OAAO,EAAE,eAAe,EAAE,MAAM,qFAAqF,CAAC;AAGtH,OAAO,EAAc,WAAW,EAAE,MAAM,oDAAoD,CAAC;AAC7F,OAAO,EAAE,sBAAsB,EAAE,MAAM,wDAAwD,CAAC;AAChG,OAAO,EAAE,oBAAoB,EAAE,MAAM,sDAAsD,CAAC;AAC5F,OAAO,EAAqB,kBAAkB,EAAE,MAAM,2DAA2D,CAAC;AAClH,OAAO,EAAE,6BAA6B,EAAE,MAAM,+DAA+D,CAAC;AAC9G,OAAO,EAAE,2BAA2B,EAAE,MAAM,6DAA6D,CAAC;AAC1G,OAAO,EAAsB,mBAAmB,EAAE,MAAM,4DAA4D,CAAC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C,CAAC;AAEF,MAAM,YAAY,GAA6C,IAAI,GAAG,CACpE,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,CAC5C,CAAC;AAEF,yEAAyE;AACzE,MAAM,UAAU,aAAa;IAC3B,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,2EAA2E;AAC3E,MAAM,UAAU,0BAA0B,CACxC,QAAgB;IAEhB,OAAO,YAAY,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;AACpC,CAAC;AAED,0EAA0E;AAC1E,MAAM,UAAU,0BAA0B,CACxC,QAAgB;IAEhB,OAAO,YAAY,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;AACpC,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type Message } from "@bufbuild/protobuf";
|
|
2
|
+
/**
|
|
3
|
+
* Serialize a resource proto into the canonical, editable Stigmer YAML form.
|
|
4
|
+
*
|
|
5
|
+
* The resource kind is derived from the message's proto type, so any
|
|
6
|
+
* registry-supported resource (an `Agent` from `stigmer.agent.get()`, an
|
|
7
|
+
* `Environment` from `stigmer.environment.get()`, …) serializes with the
|
|
8
|
+
* same call. `metadata.id` is preserved — the output is a full-fidelity
|
|
9
|
+
* representation of the stored resource, minus system-managed state.
|
|
10
|
+
*
|
|
11
|
+
* @param message - A resource proto of a registry-supported kind.
|
|
12
|
+
* @returns YAML text suitable for editing and re-applying.
|
|
13
|
+
* @throws {Error} When the message's kind is not in the manifest registry.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* import { serializeManifest } from "@stigmer/sdk";
|
|
18
|
+
*
|
|
19
|
+
* const agent = await stigmer.agent.get(agentId);
|
|
20
|
+
* const yaml = serializeManifest(agent);
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export declare function serializeManifest(message: Message): string;
|
|
24
|
+
//# sourceMappingURL=serialize.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serialize.d.ts","sourceRoot":"","sources":["../../src/manifest/serialize.ts"],"names":[],"mappings":"AAeA,OAAO,EAAU,KAAK,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAI1D;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,CAoC1D"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
// Proto → canonical Stigmer YAML serialization.
|
|
2
|
+
//
|
|
3
|
+
// Follows the platform-wide protojson parity contract (Go CLI, TS CLI
|
|
4
|
+
// output/proto.ts, mcp-server marshal.ts): `toJson` with
|
|
5
|
+
// `useProtoFieldName: true` emits snake_case field names and omits unset
|
|
6
|
+
// defaults, so the output round-trips through `parseManifest`'s strict
|
|
7
|
+
// `fromJson` without loss.
|
|
8
|
+
//
|
|
9
|
+
// Two deliberate departures from the raw protojson projection, both for
|
|
10
|
+
// the *editable manifest* use case:
|
|
11
|
+
// - `status` and `metadata.version` are stripped — they are system-managed
|
|
12
|
+
// and would be ignored (or rejected) on apply.
|
|
13
|
+
// - the envelope field is spelled `apiVersion` (the canonical form used in
|
|
14
|
+
// every repo manifest and doc); `fromJson` accepts both spellings.
|
|
15
|
+
import { toJson } from "@bufbuild/protobuf";
|
|
16
|
+
import { stringify as stringifyYaml } from "yaml";
|
|
17
|
+
import { manifestHandlerForTypeName, manifestKinds } from "./registry.js";
|
|
18
|
+
/**
|
|
19
|
+
* Serialize a resource proto into the canonical, editable Stigmer YAML form.
|
|
20
|
+
*
|
|
21
|
+
* The resource kind is derived from the message's proto type, so any
|
|
22
|
+
* registry-supported resource (an `Agent` from `stigmer.agent.get()`, an
|
|
23
|
+
* `Environment` from `stigmer.environment.get()`, …) serializes with the
|
|
24
|
+
* same call. `metadata.id` is preserved — the output is a full-fidelity
|
|
25
|
+
* representation of the stored resource, minus system-managed state.
|
|
26
|
+
*
|
|
27
|
+
* @param message - A resource proto of a registry-supported kind.
|
|
28
|
+
* @returns YAML text suitable for editing and re-applying.
|
|
29
|
+
* @throws {Error} When the message's kind is not in the manifest registry.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```ts
|
|
33
|
+
* import { serializeManifest } from "@stigmer/sdk";
|
|
34
|
+
*
|
|
35
|
+
* const agent = await stigmer.agent.get(agentId);
|
|
36
|
+
* const yaml = serializeManifest(agent);
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export function serializeManifest(message) {
|
|
40
|
+
const handler = manifestHandlerForTypeName(message.$typeName);
|
|
41
|
+
if (handler === undefined) {
|
|
42
|
+
const supported = manifestKinds()
|
|
43
|
+
.map((h) => h.yamlKind)
|
|
44
|
+
.join(", ");
|
|
45
|
+
throw new Error(`Cannot serialize ${message.$typeName} as a manifest: kind is not ` +
|
|
46
|
+
`in the manifest registry. Supported kinds: ${supported}.`);
|
|
47
|
+
}
|
|
48
|
+
const json = toJson(handler.schema, message, { useProtoFieldName: true });
|
|
49
|
+
if (json === null || typeof json !== "object" || Array.isArray(json)) {
|
|
50
|
+
throw new Error(`Cannot serialize ${handler.displayName}: unexpected non-object ` +
|
|
51
|
+
"protojson projection.");
|
|
52
|
+
}
|
|
53
|
+
const { api_version, kind, status, metadata, ...rest } = json;
|
|
54
|
+
void status;
|
|
55
|
+
const doc = {
|
|
56
|
+
apiVersion: typeof api_version === "string" && api_version !== ""
|
|
57
|
+
? api_version
|
|
58
|
+
: handler.apiVersion,
|
|
59
|
+
kind: typeof kind === "string" && kind !== "" ? kind : handler.yamlKind,
|
|
60
|
+
...(isPlainObject(metadata) && { metadata: stripSystemMetadata(metadata) }),
|
|
61
|
+
...rest,
|
|
62
|
+
};
|
|
63
|
+
// lineWidth: 0 disables wrapping (long instruction lines stay intact);
|
|
64
|
+
// blockQuote: "literal" renders multi-line strings as readable `|` blocks.
|
|
65
|
+
return stringifyYaml(doc, { lineWidth: 0, blockQuote: "literal" });
|
|
66
|
+
}
|
|
67
|
+
// metadata.version (version id, previous-version pointer, tag) is written by
|
|
68
|
+
// the server on every mutation; round-tripping it through an edit would be
|
|
69
|
+
// misleading at best. Everything else — including id — is user-meaningful.
|
|
70
|
+
function stripSystemMetadata(metadata) {
|
|
71
|
+
const { version, ...rest } = metadata;
|
|
72
|
+
void version;
|
|
73
|
+
return rest;
|
|
74
|
+
}
|
|
75
|
+
function isPlainObject(value) {
|
|
76
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=serialize.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serialize.js","sourceRoot":"","sources":["../../src/manifest/serialize.ts"],"names":[],"mappings":"AAAA,gDAAgD;AAChD,EAAE;AACF,sEAAsE;AACtE,yDAAyD;AACzD,yEAAyE;AACzE,uEAAuE;AACvE,2BAA2B;AAC3B,EAAE;AACF,wEAAwE;AACxE,oCAAoC;AACpC,6EAA6E;AAC7E,mDAAmD;AACnD,6EAA6E;AAC7E,uEAAuE;AAEvE,OAAO,EAAE,MAAM,EAAgB,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAE,SAAS,IAAI,aAAa,EAAE,MAAM,MAAM,CAAC;AAClD,OAAO,EAAE,0BAA0B,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAE1E;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,UAAU,iBAAiB,CAAC,OAAgB;IAChD,MAAM,OAAO,GAAG,0BAA0B,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IAC9D,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;QAC1B,MAAM,SAAS,GAAG,aAAa,EAAE;aAC9B,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC;aACtB,IAAI,CAAC,IAAI,CAAC,CAAC;QACd,MAAM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E,OAAO,EAAE,GAAG,IAAI,EAAE,GAAG,QAAQ,CAAC;IACtC,KAAK,OAAO,CAAC;IACb,OAAO,IAAI,CAAC;AACd,CAAC;AAED,SAAS,aAAa,CAAC,KAAc;IACnC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC9E,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stigmer/sdk",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.3.0",
|
|
4
4
|
"description": "Stigmer TypeScript SDK — typed API client for all Stigmer platform resources",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -39,11 +39,12 @@
|
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
41
|
"@connectrpc/connect": "^2.0.0",
|
|
42
|
-
"@connectrpc/connect-web": "^2.0.0"
|
|
42
|
+
"@connectrpc/connect-web": "^2.0.0",
|
|
43
|
+
"yaml": "^2.8.2"
|
|
43
44
|
},
|
|
44
45
|
"peerDependencies": {
|
|
45
46
|
"@bufbuild/protobuf": "^2.0.0",
|
|
46
47
|
"@connectrpc/connect-node": "^2.0.0",
|
|
47
|
-
"@stigmer/protos": "3.
|
|
48
|
+
"@stigmer/protos": "3.3.0"
|
|
48
49
|
}
|
|
49
50
|
}
|
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
isTransientStreamError,
|
|
9
9
|
getUserMessage,
|
|
10
10
|
getErrorReason,
|
|
11
|
+
getRecordConstraint,
|
|
11
12
|
annotateRpcError,
|
|
12
13
|
getRpcMetadata,
|
|
13
14
|
type ErrorCategory,
|
|
@@ -328,6 +329,63 @@ describe("getErrorReason", () => {
|
|
|
328
329
|
});
|
|
329
330
|
});
|
|
330
331
|
|
|
332
|
+
describe("getRecordConstraint", () => {
|
|
333
|
+
const recordViolation = (metadata: Record<string, string>) =>
|
|
334
|
+
new ConnectError("that slot is already booked", Code.AlreadyExists, undefined, [
|
|
335
|
+
{
|
|
336
|
+
desc: ErrorInfoSchema,
|
|
337
|
+
value: {
|
|
338
|
+
domain: "datastore.stigmer.ai",
|
|
339
|
+
reason: "CONSTRAINT_VIOLATION",
|
|
340
|
+
metadata,
|
|
341
|
+
},
|
|
342
|
+
},
|
|
343
|
+
]);
|
|
344
|
+
|
|
345
|
+
it("extracts the constraint name from a record-RPC violation", () => {
|
|
346
|
+
expect(getRecordConstraint(recordViolation({ constraint: "one_confirmed_per_slot" })))
|
|
347
|
+
.toBe("one_confirmed_per_slot");
|
|
348
|
+
});
|
|
349
|
+
|
|
350
|
+
it("walks the cause chain of an SDK-wrapped StigmerError", () => {
|
|
351
|
+
const connectError = recordViolation({ constraint: "one_confirmed_per_slot" });
|
|
352
|
+
const wrapped = new StigmerError(
|
|
353
|
+
"already-exists",
|
|
354
|
+
connectError.rawMessage,
|
|
355
|
+
Code.AlreadyExists,
|
|
356
|
+
{ cause: connectError },
|
|
357
|
+
);
|
|
358
|
+
expect(getRecordConstraint(wrapped)).toBe("one_confirmed_per_slot");
|
|
359
|
+
});
|
|
360
|
+
|
|
361
|
+
it("returns null when the ErrorInfo domain is not the records domain", () => {
|
|
362
|
+
const foreign = new ConnectError("workspace taken", Code.FailedPrecondition, undefined, [
|
|
363
|
+
{
|
|
364
|
+
desc: ErrorInfoSchema,
|
|
365
|
+
value: {
|
|
366
|
+
domain: "stigmer.ai",
|
|
367
|
+
reason: "SLACK_WORKSPACE_ALREADY_CONNECTED",
|
|
368
|
+
metadata: { constraint: "should_not_leak" },
|
|
369
|
+
},
|
|
370
|
+
},
|
|
371
|
+
]);
|
|
372
|
+
expect(getRecordConstraint(foreign)).toBeNull();
|
|
373
|
+
});
|
|
374
|
+
|
|
375
|
+
it("returns null when the violation carries no constraint metadata", () => {
|
|
376
|
+
expect(getRecordConstraint(recordViolation({}))).toBeNull();
|
|
377
|
+
expect(getRecordConstraint(recordViolation({ constraint: "" }))).toBeNull();
|
|
378
|
+
});
|
|
379
|
+
|
|
380
|
+
it("returns null for errors without ErrorInfo", () => {
|
|
381
|
+
expect(
|
|
382
|
+
getRecordConstraint(new ConnectError("bare", Code.AlreadyExists)),
|
|
383
|
+
).toBeNull();
|
|
384
|
+
expect(getRecordConstraint(new Error("plain"))).toBeNull();
|
|
385
|
+
expect(getRecordConstraint(null)).toBeNull();
|
|
386
|
+
});
|
|
387
|
+
});
|
|
388
|
+
|
|
331
389
|
describe("annotateRpcError / getRpcMetadata", () => {
|
|
332
390
|
it("roundtrips metadata on an error object", () => {
|
|
333
391
|
const err = new Error("test");
|